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!

entering a number in user Input Box

Status
Not open for further replies.

bac2u

MIS
Oct 18, 2002
32
US
I am trying to incorporate a user input box in a VB script. The input has to be a number, not a string, in order for the application to accept the data into the field from the user input. This is what I have:

-----------------------------------------------------------
Sub Main
' Generated by the Reflection Macro Recorder on 11-20-2003 15:43:26.18.
' Generated by Reflection for UNIX and Digital 7.00.
Dim strX as String
Dim intR as Integer

Const NEVER_TIME_OUT = 0

Dim LF As String
Dim CR As String
Dim ESC As String

LF = Chr$(rcLF)
CR = Chr$(rcCR)
ESC = Chr$(rcESC)


With Application

intR = 0
strX = InputBox("enter serial number","test")
If IsNumeric(strX) Then
intR = CLng(strX)
Else
Msgbox "Enter a serial number"
End If

End With

End Sub
-----------------------------------------------------------

And this is the error message I get when I run the script:
"Type mismatch - A variable or argument is not of the correct type. For example, a string value cannot be assigned to an integer variable. This error also occurs when using Variant variables in an expression, and the Variant cannot be converted into the correct type for the expression."

Any suggestions?

thanks,

Barb
 
This is not VBS as you can use typed variable.
Try this:
Code:
Dim intR As Long
or if you know the value is between -32768 and 32767:
Code:
intR = CInt(strX)

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top