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
 

levyuk

Well-known member
Joined
Jun 7, 2004
Messages
313
Location
Wales, UK
Programming Experience
3-5
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
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
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
 

levyuk

Well-known member
Joined
Jun 7, 2004
Messages
313
Location
Wales, UK
Programming Experience
3-5
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]
 

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
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...

 
Top Bottom