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,960 of 10,840    |
|    Lord Duran to Duane Arnold    |
|    Re: visual basic input validation intege    |
|    14 Mar 06 11:20:21    |
   
   XPost: comp.programming   
   From: lord.duran@gmail.com   
      
   Duane Arnold wrote:   
   > code_wrong wrote:   
   >   
   >> "code_wrong" wrote in message   
   >> news:4404ac4c$1_3@mk-nntp-2.news.uk.tiscali.com...   
   >>   
   >>> Visual Basic (not dot net)   
   >>> what is the best way to check the User has entered an integer into an   
   >>> InputBox?   
   >>>   
   >>> isNumeric() checks for a numeric value .. but does not notify of   
   >>> numbers with decimal places   
   >>> inputBox returns a string so I could check for decimal point??? this   
   >>> seems like overkill   
   >>>   
   >>> The value returned can be asigned into an Integer type and then a   
   >>> Single type ... the two can be compared .. but still this does not   
   >>> complain about numbers with decimal places if the fractional part is   
   >>> zero   
   >>>   
   >>> what is the simple solution?   
   >>   
   >>   
   >>   
   >> Interesting discussion , thanks for the replies.   
   >> I have decided to provide students with a pre-defined function of my   
   >> own design   
   >> please review and improve if you can   
   >> the function:   
   >>   
   >> Function isInteger(strVal As String) As Boolean   
   >>   
   >> 'if not numeric or decimal point found   
   >> If Not IsNumeric(strVal) Or InStr(strVal, ".") Then   
   >> isInteger = False   
   >> Else   
   >> isInteger = True   
   >> End If   
   >>   
   >> End Function   
   >>   
   >>   
   >>   
   >   
   > If you have tested it and it works -- it works.   
   >   
   > Does it need to be complicated for some reason?   
   >   
   > Duane :)   
      
   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.   
      
   --- 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