validate user input

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

Join Date: Sep 2008
Posts: 25
Reputation: tyserman5674 is an unknown quantity at this point 
Solved Threads: 0
tyserman5674 tyserman5674 is offline Offline
Light Poster

validate user input

 
0
  #1
Oct 3rd, 2008
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.

  1. Private Sub txtInterestRate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInterestRate.TextChanged
  2. Try
  3.  
  4. If Me.txtInterestRate.Text.Length = 0 Then 'reads interest rate text box
  5. Me.errInput.SetError(Me.txtInterestRate, "Please Enter a valid value") 'if 0 gives error
  6.  
  7. ElseIf Not IsNumeric(txtInterestRate.Text) Then 'checks input for numeric value
  8. Me.errInput.SetError(Me.txtInterestRate, "Please Enter a valid Numeric value") 'if non-numerics gives error
  9. Throw New Exception("Please enter a valid numeric value")
  10.  
  11. ElseIf txtInterestRate.Text = 0 Then 'checks input for numeric value
  12. Me.errInput.SetError(Me.txtLoanAmount, "Please Enter a Non Zero valid Numeric value") 'if non-numerics gives error
  13. Throw New Exception("Please enter a valid Non Zero numeric value")
  14.  
  15. End If
  16.  
  17. Catch ex As Exception 'exception handeler for error input
  18. MsgBox(ex.Message) 'displays error
  19. Me.txtInterestRate.Text = ("")
  20. End Try
  21. End Sub
Any help would really be appreciated!
Thanks,
Ken
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: validate user input

 
0
  #2
Oct 3rd, 2008
What about right after Try inserting

If Me.txtInterestRate.Text <> ""
/// do all of your stuff
End If
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 25
Reputation: tyserman5674 is an unknown quantity at this point 
Solved Threads: 0
tyserman5674 tyserman5674 is offline Offline
Light Poster

Re: validate user input

 
0
  #3
Oct 4th, 2008
rapture,
Thank you very much for your reply. I added your line of code to all the text boxes and it worked great.
Thanks,
Ken
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 25
Reputation: tyserman5674 is an unknown quantity at this point 
Solved Threads: 0
tyserman5674 tyserman5674 is offline Offline
Light Poster

Re: validate user input

 
0
  #4
Oct 7th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: validate user input

 
0
  #5
Oct 7th, 2008
You may want to check that when user presses Ok-button (or any similar button):
  1. Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click
  2. ' Check empty text
  3.  
  4. If Me.txtInterestRate.Text.Trim = "" Then
  5. MessageBox.Show("Please enter interest rate", _
  6. "Missing Information", _
  7. MessageBoxButtons.OK, _
  8. MessageBoxIcon.Warning)
  9. Me.txtInterestRate.Focus() ' Set focus to field if you want
  10. End If
  11.  
  12. End Sub
or "integrate" this with rapture's answer:
  1. If Me.txtInterestRate.Text <> ""
  2. /// do all of your stuff
  3. Else
  4. MessageBox.Show("Please enter interest rate", _
  5. "Missing Information", _
  6. MessageBoxButtons.OK, _
  7. MessageBoxIcon.Warning)
  8. End If
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 25
Reputation: tyserman5674 is an unknown quantity at this point 
Solved Threads: 0
tyserman5674 tyserman5674 is offline Offline
Light Poster

Re: validate user input

 
0
  #6
Oct 8th, 2008
Teme64,
Thank you for your input, it works great now. I just couldn't figure that one out.
Thanks,
tyserman5674
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC