954,228 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Input Box Validation

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!

petro
Newbie Poster
4 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

Create a function that checks for numbers only.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
Create a function that checks for numbers only.

How do you do this?

petro
Newbie Poster
4 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

Do you know how to write a function?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
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

petro
Newbie Poster
4 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Cheers!

Got it working now!

petro
Newbie Poster
4 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

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.

nyashaC
Newbie Poster
19 posts since Aug 2007
Reputation Points: 19
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You