Hi,

I have this project that i have made, although i have been trying to figure out how to make it so that the user can only enter integers in the input box and no letters (if they do the program crashes)

Can anyone help us out/guide me in the right direction...

Dim num1 As Integer
Dim num2 As Integer
Dim counter As Integer


Case 2
MsgBox("Begin execution", MsgBoxStyle.Information)
num1 = InputBox("Please enter a number")
MsgBox("Command executed", MsgBoxStyle.Exclamation)
'shows two message boxes
'asks the user to enter a number via an input box
Case 3
MsgBox("Begin execution", MsgBoxStyle.Information)
num2 = InputBox("Please enter another number")
MsgBox("Command executed", MsgBoxStyle.Exclamation)
'shows two message boxes
'asks the user to enter another number via an input box


Thanks!

Recommended Answers

All 7 Replies

Member Avatar for iamthwee

Create a function that checks for numbers only.

Create a function that checks for numbers only.

How do you do this?

Member Avatar for iamthwee

Do you know how to write a function?

Do you know how to write a function?

I meant as what would be the coding for it, I am all new to this VB.net and this is my first project. (its a simple 'machine cycle simulation' of two numbers being added)

Thanks

Hi,

use Val() function check this :

num1 =Val(InputBox("Please enter a number"))

Even if user enters some Text chars, u get its value as zero..
May be u can write check after that to enter some Valid Value

Regards
Veena

Cheers!

Got it working now!

Do not use the plain textbox on your form instead use a masked text box.
Set the following properties for the masked textbox
1. For the mask select numeric and increase the maximum length up to what you desire
2. Set the RejectInputOnFirstFailure property to true.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.