Discussion:
lowercase lettere and upper case lettere vb.net
(too old to reply)
madushka930
2011-10-09 13:13:38 UTC
Permalink
iwant to find the pressed key is lower or upper how can i do this..
please help me... i tried this .. but i have got an same result at
every time..

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

If e.KeyChar.IsLower(ChrW(Keys.A)) Then
MsgBox("a")
Else
MsgBox("A")
End If

END SUB
Peter Duniho
2011-10-09 20:03:18 UTC
Permalink
Post by madushka930
iwant to find the pressed key is lower or upper how can i do this..
please help me... i tried this .. but i have got an same result at
every time..
System.Char.IsLower() is a static method, requiring that you pass in the
character you want to know about. The code you posted always passes the
same character to the method (the character generated by converting the
non-character value of Keys.A to a character), and so will always have
the same result.

Try instead:

If System.Char.IsLower(e.KeyChar) Then
MsgBox("a")
Else
MsgBox("A")
End If

Note that had you tried to write that code in C#, the compiler would
have refused to let you call the static method as an instance method.
VB.NET works great for a lot of things, but if you're going to use it,
it's worth remembering that the language is a lot more flexible in
certain ways and can allow you to write code that isn't literally doing
what it might look to the human reader that it's doing.

Pete

Loading...