Inputbox integer:

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
I am using an inputbox to get a "partid" which is an integer. What code do I need to check if cancel is pushed on the inputbox. There is a conflict between string and integer. Cancel returns a string which can't be checked if the inputbox answer is set up for an integer. Do you know how to work around this without creating your own input box.
Just curious, I will create my own box and assign the answer to -1 if cancel is pushed. Then I can If/then for a positive number and use it that way...

Any other ways out there?

Thanks
 
I think you can convert the string to an int by doing this I think CINT(your string)

Not sure if that is correct, will have to check when i get hjome
 
VB.NET:
dim intVariable as integer
if isnumeric(textbox.text) = true then
intvariable=convert.toint32(textbox.text)
else
messagebox.show("must be numeric")
textbox.focus
end if
 
You can also restrict the textbox to numeric values only by adding this code to the keypress event of the textbox
VB.NET:
[size=2][/size][size=2][color=#008000]'Allows only numeric values into the ContactNumber textbox

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] e.KeyChar.IsNumber(e.KeyChar) = [/size][size=2][color=#0000ff]False[/color][/size][size=2] [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]e.Handled = [/size][size=2][color=#0000ff]True

[/color][/size][size=2][/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If[/color][/size]
[size=2][color=#0000ff]
[/color][/size]
 
Thanks Guys...

Thanks a lot, I have received lots of help from everyone at this site..
here is what I used:

Dim prompt AsString

Dim ShopfloorID AsString

prompt = "Enter Shop Floor Id."

ShopfloorID = InputBox(prompt, , "0")

If ShopfloorID = "" Then

'do nothing cancel was entered

Else

If ShopfloorID = "0" Then

'go to the part table to find it.

Dim part1 AsNew frmPart1

part1.Show()

Else

'go straight to the shopfloor table

iCurrentShopFloor = CInt(ShopfloorID)

Dim SFTime AsNew frmShopFloorTime

SFTime.ShowDialog()

EndIf

EndIf


thanks again...

 

Latest posts

Back
Top