Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Note--- However the factorial programs would always have an limitation in VB that if you will add more

than 20 it will give you an exception!!

Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
txtoutput.Enabled = False
End Sub

Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btncalculate.Click
Dim input, k, counter As Integer
Dim factorial As Long
txtinput.Focus()

If txtinput.Text = "" Then


MsgBox("Please Enter a Number!", MsgBoxStyle.Critical, "Error")
k = 1
End If

factorial = 1
If (k = 0) Then
input = txtinput.Text
For counter = 1 To input
factorial = factorial * counter
Next
txtoutput.Text = factorial
End If
End Sub
End Class

You might also like