943,657 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 11554
  • VB.NET RSS
Aug 10th, 2007
0

Input Box Validation

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
petro is offline Offline
4 posts
since Aug 2007
Aug 11th, 2007
0

Re: Input Box Validation

Create a function that checks for numbers only.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 11th, 2007
0

Re: Input Box Validation

Click to Expand / Collapse  Quote originally posted by iamthwee ...
Create a function that checks for numbers only.
How do you do this?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
petro is offline Offline
4 posts
since Aug 2007
Aug 11th, 2007
0

Re: Input Box Validation

Do you know how to write a function?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 11th, 2007
0

Re: Input Box Validation

Click to Expand / Collapse  Quote originally posted by iamthwee ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
petro is offline Offline
4 posts
since Aug 2007
Aug 12th, 2007
0

Re: Input Box Validation

Hi,

use Val() function check this :

VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Aug 13th, 2007
0

Re: Input Box Validation

Cheers!

Got it working now!
Last edited by petro; Aug 13th, 2007 at 9:17 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
petro is offline Offline
4 posts
since Aug 2007
Aug 13th, 2007
1

Re: Input Box Validation

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.
Reputation Points: 19
Solved Threads: 0
Newbie Poster
nyashaC is offline Offline
19 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: .net framework notes
Next Thread in VB.NET Forum Timeline: Single Sign On





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC