I'm getting a warning at the end of my code that says, Warning 1 Function 'Result' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. The code works fine, but can someone explain why I'm getting this warning and is it important?
'This code will calculate the two numbers the user inputs into the textboxes.
'
Public Class Calculator
'this code will call AddedNum Function
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Try
AddedNum(CInt(txtFirstNum.Text), CInt(txtSecondNum.Text), "+")
Catch e1 As OverflowException
MessageBox.Show("Number too large.", "Over Flow")
Catch e2 As Exception
MessageBox.Show("Enter a number.")
End Try
End Sub
' this code will do the calculation for the AddedNum
Function AddedNum(ByVal a As Integer, ByVal b As Integer, ByVal c As String) As Integer
Dim Total As String
Total = a + b.ToString
txtResult.Text = Total
Return Total = a + b.ToString
End Function
'This code will call the Function SubtractedNum
Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
Try
SubtractedNum(CInt(txtFirstNum.Text), CInt(txtSecondNum.Text), "-")
Catch e1 As OverflowException
MessageBox.Show("Number too large.", "Over Flow")
Catch e2 As Exception
MessageBox.Show("Enter a number.")
End Try
End Sub
'This code will do the calculation for the SubtractedNum
Function SubtractedNum(ByVal a As Integer, ByVal b As Integer, ByVal c As String) As integer
Dim Total As String
Total = a - b.ToString
txtResult.Text = Total
Return Total = a - b.ToString
End Function
'This code will call the Function MultiplyNum
Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click
Try
MultiplyNum(CInt(txtFirstNum.Text), CInt(txtSecondNum.Text), "*")
Catch e1 As OverflowException
MessageBox.Show("Number too large.", "Over Flow")
Catch e2 As Exception
MessageBox.Show("Enter a number.")
End Try
End Sub
'This code will calculate the MultipLyNum
Function MultiplyNum(ByVal a As Integer, ByVal b As Integer, ByVal c As String) As Integer
Dim Total As String
Total = a * b.ToString
txtResult.Text = Total
Return Total = a * b.ToString
End Function
'This code will call the Function DivideNum
Private Sub btnDevide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDevide.Click
Try
DivideNum(CInt(txtFirstNum.Text), CInt(txtSecondNum.Text), "/")
Catch e1 As OverflowException
MessageBox.Show("Number too large.", "Over Flow")
Catch e2 As DivideByZeroException
MessageBox.Show("Error.")
Catch e3 As Exception
MessageBox.Show("Enter a number.")
End Try
End Sub
'This code will calculate DivideNum
Function DivideNum(ByVal a As Integer, ByVal b As Integer, ByVal c As String) As Integer
Dim Total As String
Total = a / b.ToString
txtResult.Text = Total
Return Total = a / b.ToString
End Function
'This code will call the PowNum Function
Private Sub btnPow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPow.Click
Try
PowNum(CInt(txtFirstNum.Text), CInt(txtSecondNum.Text), "^")
Catch e1 As OverflowException
MessageBox.Show("Number too large.", "Over Flow")
Catch e2 As Exception
MessageBox.Show("Enter a number.")
End Try
End Sub
'This code will calculate the PowNum
Function PowNum(ByVal a As Integer, ByVal b As Integer, ByVal c As String) As Integer
Dim Total As String
Total = a ^ b.ToString
txtResult.Text = Total
Return Total = a ^ b.ToString
End Function
'This code will clear the textboxes
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtFirstNum.Clear()
txtSecondNum.Clear()
txtResult.Clear()
End Sub
Function Result(ByVal a As Integer, ByVal b As Integer, ByVal c As String)
If c = "+" Then
Return a + b
End If
If c = "-" Then
Return a - b
End If
If c = "*" Then
Return a * b
End If
If c = "/" Then
Return a / b
End If
If c = "^" Then
Return a ^ b
End If
End Function
End Class