Input Box Validation

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2007
Posts: 4
Reputation: petro is an unknown quantity at this point 
Solved Threads: 0
petro petro is offline Offline
Newbie Poster

Input Box Validation

 
0
  #1
Aug 10th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Input Box Validation

 
0
  #2
Aug 11th, 2007
Create a function that checks for numbers only.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 4
Reputation: petro is an unknown quantity at this point 
Solved Threads: 0
petro petro is offline Offline
Newbie Poster

Re: Input Box Validation

 
0
  #3
Aug 11th, 2007
Originally Posted by iamthwee View Post
Create a function that checks for numbers only.
How do you do this?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Input Box Validation

 
0
  #4
Aug 11th, 2007
Do you know how to write a function?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 4
Reputation: petro is an unknown quantity at this point 
Solved Threads: 0
petro petro is offline Offline
Newbie Poster

Re: Input Box Validation

 
0
  #5
Aug 11th, 2007
Originally Posted by iamthwee View Post
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Input Box Validation

 
0
  #6
Aug 12th, 2007
Hi,

use Val() function check this :

  1. 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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 4
Reputation: petro is an unknown quantity at this point 
Solved Threads: 0
petro petro is offline Offline
Newbie Poster

Re: Input Box Validation

 
0
  #7
Aug 13th, 2007
Cheers!

Got it working now!
Last edited by petro; Aug 13th, 2007 at 9:17 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 19
Reputation: nyashaC is an unknown quantity at this point 
Solved Threads: 0
nyashaC nyashaC is offline Offline
Newbie Poster

Re: Input Box Validation

 
1
  #8
Aug 13th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC