| | |
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 |
Tag cloud for VB.NET
.net 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code combobox component convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output passingparameters peertopeervideostreaming picturebox picturebox1 port print printing problem problemwithinstallation project remove save searchbox searchvb.net select serial server shutdown soap sorting survey table tcp temperature text textbox timer toolbox trim update updown user validation vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





