home bbs files messages ]

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,967 of 10,840   
   Lord Duran to All   
   That example is not good   
   18 Mar 06 16:52:21   
   
   XPost: comp.programming   
   From: lord.duran@gmail.com   
      
   Rick Rothstein [MVP - Visual Basic] wrote:   
   >>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   
   >   
   >   
      
   I don't know how robust that things is, but your example would not work   
   here - because CStr(Val("12e3")) = "12000" which is not equal to "12e3"   
   when comparing strings.   
      
   --- 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