Currently working on the status bar for application. I would like the status bar to display message errors if a user makes an invalid entry.
I have a module which contains the main procedure and procedures to change the text property of my status bar. A Call is made to the procedures from one of the forms that requires the user input. The application compliles but I get an unhandled exception of type 'System.Null ReferenceException' Object reference not set to an instance of an object.
I have relevant code is shown below:
Line 15 above is where the exception is occuring but I am not sure why. Any ideas?Code:Module MainMod 02 03 Public sErrorMessage As String 04 05 Private frmFinancialCalculations As frmFinancialCalculations 06 07 Public Sub Main() 08 09 Application.Run(frmFinancialCalculations) 10 11 End Sub 12 13 Public Sub DisplayErrorMessage() 14 15 frmFinancialCalculations.sbFinancialCalculations.Text = sErrorMessage 'This is where exception is happening 16 17 MessageBox.Show(sErrorMessage, "Financial Calculations") 18 19 End Sub 20 Public Sub ClearErrorMessage() 21 22 frmFinancialCalculations.sbFinancialCalculations.Text = "" 23 24 End Sub 25 End Module 26 27 =================================================================================== 28 29 30 Private Sub btnCalculate_Click(ByVal sender As System.Object, _ 31 ByVal e As System.EventArgs) Handles btnCalculate.Click 32 33 If rdoFutureValue.Checked = True Then ' Determine which radio buton is called 34 If ValidEntry(txtMonthlyInvestment.Text, 100, 1000) Then 35 If ValidEntry(txtInterestRate.Text, 0, 24) Then 36 If ValidEntry(txtYears.Text, 1, 65) Then 37 Me.CalculateFutureValue() 38 txtFutureValue.Focus() 39 Else 40 sErrorMessage = "Years must be a number between 1 and 65." 41 Call DisplayErrorMessage() 42 'MessageBox.Show("Years must be a number between 1 and 65.", _ 43 '"Entry error") 44 txtYears.Focus() 45 End If 46 Else 47 sErrorMessage = "Interest rate must be a number between 0 and 24." 48 Call DisplayErrorMessage() 49 'MessageBox.Show("Interest rate must be a number between 0 and 24.", _ 50 ' "Entry error") 51 txtInterestRate.Focus() 52 End If 53 Else 54 sErrorMessage = "Monthly investment must be a number between 100 and 1,000." 55 Call DisplayErrorMessage() 56 'MessageBox.Show("Monthly investment must be a number between 100 and 1,000.", _ 57 '"Entry error") 58 txtMonthlyInvestment.Focus() 59 End If 60 ElseIf rdoMonthlyInvestment.Checked = True Then 61 If ValidEntry(txtInterestRate.Text, 0, 24) Then 62 If ValidEntry(txtYears.Text, 1, 65) Then 63 If ValidEntry(txtFutureValue.Text, 1000, 100000) Then 64 Me.CalculateMonthlyInvestment() 65 txtMonthlyInvestment.Focus() 66 Else 67 sErrorMessage = "Future Value must be a number between 1,000 and 1,000,00." 68 Call DisplayErrorMessage() 69 'MessageBox.Show("Future Value must be a number between 1,000 and 1,000,00.", _ 70 '"Entry error") 71 txtFutureValue.Focus() 72 End If 73 Else 74 sErrorMessage = "Interest rate must be a number between 0 and 24." 75 Call DisplayErrorMessage() 76 'MessageBox.Show("Interest rate must be a number between 0 and 24.", _ 77 '"Entry error") 78 txtInterestRate.Focus() 79 End If 80 Else 81 sErrorMessage = "Years must be a number between 1 and 65." 82 Call DisplayErrorMessage() 83 'MessageBox.Show("Years must be a number between 1 and 65.", _ 84 '"Entry error") 85 txtYears.Focus() 86 End If 87 Else 88 sErrorMessage = "Years must be a number between 1 and 65." 89 Call DisplayErrorMessage() 90 'MessageBox.Show("Please specify the calculation as Future Value or Monthly investment", _ 91 '"Entry error") 92 GroupBox1.Focus() ' If no radio buttons are selected 93 94 End If 95 End Sub




Reply With Quote