I am writing a simple code using a function to return a value.
When I run the code, the function always returns one, therefore giving me a logical error. Any and all help is appreciated... Thank you!!
Here is the code:
Private Function Factorial(ByVal intNumber As Integer) As Integer
Dim intFac As Integer = 1
Dim i As Integer
For i = 2 To intNumber
intFac = intFac * 1
Next
Factorial = intFac
End Function
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim intNumber, intFactorial As Integer
Try
intNumber = Convert.ToInt32(txtNumber.Text)
intFactorial = Factorial(intNumber)
Debug.WriteLine(intFactorial, "Factorial = ")
txtFactorial.Text = intFactorial.ToString()
Dim i As Integer
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
When I run the code, the function always returns one, therefore giving me a logical error. Any and all help is appreciated... Thank you!!
Here is the code:
Private Function Factorial(ByVal intNumber As Integer) As Integer
Dim intFac As Integer = 1
Dim i As Integer
For i = 2 To intNumber
intFac = intFac * 1
Next
Factorial = intFac
End Function
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim intNumber, intFactorial As Integer
Try
intNumber = Convert.ToInt32(txtNumber.Text)
intFactorial = Factorial(intNumber)
Debug.WriteLine(intFactorial, "Factorial = ")
txtFactorial.Text = intFactorial.ToString()
Dim i As Integer
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub