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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get InputBox to accept a number as a number not a string 1

Status
Not open for further replies.

bac2u

MIS
Oct 18, 2002
32
US
I'm really stupid at this, but I'm trying to do a VB macro in Emulator software (Reflections) and the thing compiles and seems to work okay except for one little thing. It doesn't put the user's input data that is prompted by the InputBox into the application I'm running the macro in.

The description for when to use InputBox is this:
Description

"Opens a dialog box containing a prompt and a text box for user input, and returns the contents of the text box after the user clicks OK."

My statement is this:

Dim eeSerial As String
eeSerial = Session.InputBox("Please Enter Employee Serial #", "Serial#")
.Transmit CR
With Session
.Transmit "1" & CR

It doesn't put the number in the field because the field is numeric, not alphanumeric. What is the proper statement to use to prompt for user input of a number which will actually be read as a number not text?

Any help would be greatly appreciated.

 
You'll need to convert the string to a numeric by using cint, cdbl, ccur, csng, clng.

David Paulson

 
You can also use the IsNumeric function to check the input is numeric before using one of the conversion functions (CLng etc) to cast it as a number.

Paul Bent
Northwind IT Systems
 
I don't know how to incorporate the function you mention (I think I would need CInt) into the code I already have. Can you help me with that?
 
Something like this:
Code:
Dim strX as String
Dim intR as Integer

intR = 0
strX = InputBox("Enter a number","Test")
If IsNumeric(strX) Then
  intR = CInt(strX)
Else
  MsgBox "I said ""Enter a number""!", vbInformation
End If
Obviously you would also need to check that the value returned is within the range acceptable for an integer (-32768 -> +32767). Personally I'd use a Long.

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top