If e.KeyChar = CChar(ChrW(Keys.Back)) Or e.KeyChar = CChar(".") Then
e.Handled = False
Else
e.Handled = True....
i want explanations for the above code..i know this code for validate the textbox in vb.net..
but i can't understand the use of CChar,ChrW,keys.back...
so telll me wht is use of CChar,ChrW,Keys.back>
AlanPosted Aug 25, 2007, 8:17 AM
CChar() takes a String as an argument and converts the first character to the Char datatype which represents a unicode character (2 bytes). For example:
Dim c As Char = CChar("abc") ' c is equal to "a"c
ChrW() takes an Integer as an argument and returns the unicode character (as a Char) which has that number. For example:
Dim letter As Char = ChrW(65) ' letter is equal to "A"c
Notice that to get a Char literal in VB, you follow it with 'c'. So,
Dim char1 As String = "B" ' String literal
Dim char2 As Char = "B"c ' Char literal
Although these may look the same, they are in fact different data types.
So, in the expression: CChar(ChrW(Keys.Back)), Keys.Back is a member of the Keys Enum (similar to an Integer0 and so you need to apply ChrW() to it, to get its Char equivalent. The user of CChar() is superfluous because ChrW is already a Char so you should just use ChrW(Keys.Back) instead.