| | |
validate user input
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 25
Reputation:
Solved Threads: 0
Hi all,
I have different text boxes the I need to validate the user inut. The code that I have (example) does work, the problem is that if there is absolutly nothing in the text box I don't want to get the error message. If I have a starting "0", physically in the text box, or "non-numeric value" then I do want the error message. What happens is when I "clear" everything in the boxes then I get the error also but don't want it if nothing is in the boxes.
Any help would really be appreciated!
Thanks,
Ken
I have different text boxes the I need to validate the user inut. The code that I have (example) does work, the problem is that if there is absolutly nothing in the text box I don't want to get the error message. If I have a starting "0", physically in the text box, or "non-numeric value" then I do want the error message. What happens is when I "clear" everything in the boxes then I get the error also but don't want it if nothing is in the boxes.
VB.NET Syntax (Toggle Plain Text)
Private Sub txtInterestRate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInterestRate.TextChanged Try If Me.txtInterestRate.Text.Length = 0 Then 'reads interest rate text box Me.errInput.SetError(Me.txtInterestRate, "Please Enter a valid value") 'if 0 gives error ElseIf Not IsNumeric(txtInterestRate.Text) Then 'checks input for numeric value Me.errInput.SetError(Me.txtInterestRate, "Please Enter a valid Numeric value") 'if non-numerics gives error Throw New Exception("Please enter a valid numeric value") ElseIf txtInterestRate.Text = 0 Then 'checks input for numeric value Me.errInput.SetError(Me.txtLoanAmount, "Please Enter a Non Zero valid Numeric value") 'if non-numerics gives error Throw New Exception("Please enter a valid Non Zero numeric value") End If Catch ex As Exception 'exception handeler for error input MsgBox(ex.Message) 'displays error Me.txtInterestRate.Text = ("") End Try End Sub
Thanks,
Ken
•
•
Join Date: Sep 2008
Posts: 25
Reputation:
Solved Threads: 0
Hi All,
I have been trying to figure out another problem with this program, maybe some one can help me out.
I need some type of code so if the text field is left completey empty it will give an error and tell the user to please input a number.
I just haven't been able to figure it out.
Help Please,
Ken
I have been trying to figure out another problem with this program, maybe some one can help me out.
I need some type of code so if the text field is left completey empty it will give an error and tell the user to please input a number.
I just haven't been able to figure it out.
Help Please,
Ken
You may want to check that when user presses Ok-button (or any similar button):
or "integrate" this with rapture's answer:
VB.NET Syntax (Toggle Plain Text)
Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click ' Check empty text If Me.txtInterestRate.Text.Trim = "" Then MessageBox.Show("Please enter interest rate", _ "Missing Information", _ MessageBoxButtons.OK, _ MessageBoxIcon.Warning) Me.txtInterestRate.Focus() ' Set focus to field if you want End If End Sub
VB.NET Syntax (Toggle Plain Text)
If Me.txtInterestRate.Text <> "" /// do all of your stuff Else MessageBox.Show("Please enter interest rate", _ "Missing Information", _ MessageBoxButtons.OK, _ MessageBoxIcon.Warning) End If
Teme64 @ Windows Developer Blog
![]() |
Similar Threads
- new python user needs a bit of help (Python)
- Validate username/password vs SQL Db (C#)
- how to get 1 submit button to validate user's choice (ASP)
- Handling Invalid User Input? (C)
- about shopping center (PHP)
- C++ Program Contest (C++)
- How to write javascript regular expression for this case? (JSP)
- Creating a GUI that accepts user input help (Java)
- Can u help me with hangman code in vb.net please :( (VB.NET)
Other Threads in the VB.NET Forum
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add arithmetic array assignment basic binary bing box button buttons center code combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel file-dialog firewall folder google hardcopy image images isnumericfuntioncall listview login math memory mobile ms mssqlbackend mysql navigate net networking opacity output pan peertopeervideostreaming picturebox picturebox1 plugin port print printpreview problemwithinstallation project record reports" reuse save savedialog serial server sorting sql storedprocedure string temp text textbox timer toolbox updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf





