validating event procedure

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

Join Date: Aug 2009
Posts: 2
Reputation: itzcrakalakin is an unknown quantity at this point 
Solved Threads: 0
itzcrakalakin itzcrakalakin is offline Offline
Newbie Poster

validating event procedure

 
0
  #1
Aug 2nd, 2009
I am trying to create a retirement calculator. I have finished my design and coded my calculate button. Now I am trying to use the validating event procedue to ensure that data entered into the text boxes is numeric. Here is what I have, the program builds successfully however when non-numeric data is entered I keep getting a nullReferenceException.

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="ThomasChantell-Lab4"
StackTrace:
at ThomasChantell_Lab4.Form1.txtAge_Validating(Object sender, CancelEventArgs e) in C:\Documents and Settings\TACO\My Documents\Visual Studio 2008\Projects\ThomasChantell-Lab4\ThomasChantell-Lab4\Lab4-ThomasChantell.vb:line 72
at System.Windows.Forms.Control.OnValidating(CancelEventArgs e)
at System.Windows.Forms.Control.NotifyValidating()
at System.Windows.Forms.Control.PerformControlValidation(Boolean bulkValidation)
at System.Windows.Forms.ContainerControl.ValidateThroughAncestor(Control ancestorControl, Boolean preventFocusChangeOnError)
InnerException:

Here is my code:



Private Sub txtAge_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles _
txtAge.Validating, _
txtYearlySalary.Validating, _
txtRaise.Validating, _
txtRetireAge.Validating
Dim txtBox As TextBox
Dim prompt As String
txtBox = CType(sender, TextBox)
If IsNumeric(txtBox.Text) Then
e.Cancel = False
Else
prompt = "Enter a number in " & txtBox.Tag.ToString
MessageBox.Show(prompt, "Invalid Input: " & txtBox.Tag.ToString, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtBox.Text = ""
e.Cancel = True
End If
End Sub
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,613
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 469
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: validating event procedure

 
0
  #2
Aug 3rd, 2009
Welcome itzcrakalakin,
Use code tags to post source code.
for example,

[code=vb.net]
... statements.
[/code]

What will be the value of Tag property? I think you have to set value of Tag property.
Failure is not fatal, but failure to change might be. - John Wooden
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