validation - vb.net Chr KeyPress function -
when validating textboxes in vb.net, use .chr or .chrw function define valid ranges of ascii values can entered. today came across i've not had before, had use function in e.keychar <> chr(156)
format, replace value 156 value gbp sign, or £
however, after finding out online via ascii tables ascii value 156, ran code, , wouldn't let me enter £. fix this? there i'm missing?
private sub txtfval_keypress(sender object, e keypresseventargs) handles txtfval.keypress if e.keychar <> chr(156) andalso e.keychar <> chr(46) andalso e.keychar <> chr(44) andalso e.keychar = chrw(keys.oemcomma) _ andalso (e.keychar < chr(48) orelse e.keychar > chr(57)) andalso e.keychar <> chr(8) e.handled = true end if end sub
instead of having lookup ascii number specify char suffixing string c
- in vb.net indicates you've specified char literal:
if e.keychar <> "£"c andalso ...
edit:
here's more clean if
-statement, see if works:
if char.isnumber(e.keychar) = false andalso e.keychar <> "£"c _ andalso e.keychar <> ","c andalso e.keychar <> "."c _ andalso e.keychar <> chr(8) e.handled = true end if
Comments
Post a Comment