Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.visual.basic    |    MS Visual Basic discussions, NOT dot-net    |    10,840 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 9,964 of 10,840    |
|    Rick Rothstein [MVP - Visual Basic] to All    |
|    Re: visual basic input validation intege    |
|    14 Mar 06 08:38:02    |
      XPost: comp.programming       From: rickNOSPAMnews@NOSPAMcomcast.net              > It seems to me that a simple cast and cast back can be used for       validation:       >       > Function MyIsNumeric(ByVal cand as String) as Boolean       > If cand = CStr(CLng(cand)) Then       > MyIsNumeric = True       > Else       > MyIsNumeric = False       > End Function       >       > But take that with a grain of salt, I haven't actually tested it.              The problem with that approach (whether you use CLng or Val (as Dean       suggested), is it will show as valid a number from that is normally useless       in an input validation scenario (which is what this thread is about). The       reason is because when a programmer uses such routines, they are NOT really       interested in whether the entry is a number; rather the programmer usually       wants the entry to be all digits (such as in a phone number). As an example,       let's say the programmer wanted the user to input a 4-digit number for       whatever reason and, to eliminate the need to check the length of the entry,       he/she sets the MaxLength property of the TextBox being used to accept the       user's entry to 4. Is everything okay then? Nope! Your routine will fail the       programmer for an entry like 12e3 (notice the embedded "e"). Your routine       would return True because 12e3 is a valid number... it is 12000 when       expanded... but note that is a 5-digit number, not 4-digit number as       required, and that would probably screw up the program when it tried to use       it.              Rick              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca