Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple prompt to get an integer from a user? 1

Status
Not open for further replies.

Paladyr

Programmer
Apr 22, 2001
508
0
0
US
Is there a "built-in" prompt with an input field that will allow me to grab an integer from the user??? Something like:

intExample = vbUserPrompt

and vbUserPrompt will return whatever the user enters??? Thanks!
 
Hey Paladyr,

Try the following inside your code:

InputBox "Please insert an integer", "Insert Integer"
 
Okay, it won't let me assign the input to anything??? How do I get what the user enters into an integer???
 
Dim Result

Result = InputBox ("Enter an integer here")

The integer is now storred into the variable Result.
 
I just figured it out, it returns a string... I was trying to grab an integer.. Thanks!
 
Take the returned string, and test it with IsNumeric.

If it passes the test, bung it through CInt and look smug.

If it fails, slap the user with a robotic arm of something, and "invite" the user to try again...
 
Dim strResult as String
Dim intResult As Integer
Dim lngErr as Long
Do
strResult = InputBox ("Enter an integer here")
On Error resume next
intResult = Cint(strResult)
lngErr = Err.Number
On error goto 0
if lngErr = 0 then
* User could enter "-1"
if intResult >= 0 then exit do
End if
Loop
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thank you all for your suggestions :).
 
'Try this
Function AskForNum() As Integer
Dim ans%
On Error Resume Next
AskForNum = 42 'default value
AskForNum = InputBox("Enter an integer here")
'if entry was invalid default is returned
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top