‘Declare static variables MK_n and MK_factorial as Byte. ‘Display the label “Byte” under the label “Data Type” MK_n = MK_n + 1 If (MK_n = 1) then MK_factorial = 1 Else MK_factorial = MK_factorial * MK_n End If ‘Display the values of MK_n and MK_factorial in the corresponding text boxes.
I have come up with this code:
Private Sub AH_Button_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AH_Button_1.Click Dim AH_n As Byte Dim AH_factorial As Byte Dim AH_Textbox_1 As Byte AH_Label_5.Text = "Byte" AH_n = AH_n + 1 If AH_n = 1 Then AH_factorial = 1 Else AH_factorial = AH_factorial * AH_n End If AH_TextBox_2.Text = AH_factorial End Sub
AH_TextBox1 is supposed to be the N value input by the user, while AH_TextBox2 is supposed to show the final factorial value.
The problem I'm having is that the value of AH_factorial (TextBox2) keeps returning 1 no matter what the N value is.
Can anyone point out the flaw in my code?