| | |
validating event procedure
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Call a button click event under another sub procedure (VB.NET)
- [DELPHI] how to set event procedure runtime? (Pascal and Delphi)
- Update query in event procedure for Form (Visual Basic 4 / 5 / 6)
- three timer component problem inside my checkbox event procedure (Pascal and Delphi)
- Error when making an event procedure in Visual Basic (C)
Other Threads in the VB.NET Forum
- Previous Thread: MessageBox in VB.Net
- Next Thread: VB2008 and Microsoft Access Database File
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy image images insert intel internet listview login math mobile monitor ms navigate net networking opacity output passingparameters peertopeervideostreaming picturebox picturebox1 port print problem problemwithinstallation project reports" save savedialog searchbox searchvb.net select serial soap string table tcp text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf






