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,930 of 10,840   
   Steve Gerrard to tac@tac.co.uk   
   Re: viusal basic input validation intege   
   28 Feb 06 19:43:29   
   
   XPost: comp.programming   
   From: mynamehere@comcast.net   
      
   "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?   
   >   
      
   "simple solution" is always a relative term in this NG :)   
      
   For integers, I would do this test, which deals with fractional entries as   
   well:   
      
   Private Sub Command1_Click()   
   Dim A As Single   
   Dim B As Long   
   Dim C As Single   
   Dim bNum As Boolean   
   Dim sInput As String   
      
   sInput = InputBox("enter an integer", , "0")   
   bNum = IsNumeric(sInput)   
   If bNum Then   
       A = CSng(sInput)   
       B = CLng(A)   
       C = CSng(B)   
   End If   
   If bNum And C = A Then   
       MsgBox "good dog, you entered " & B   
   Else   
       MsgBox "How is " & sInput & " an integer?"   
   End If   
      
   End Sub   
      
   That way, the user can enter 3E7 if they want, a perfectly valid way of   
   entering   
   30,000,000 :)   
      
   --- 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