Public Class Form1
Private Sub GetFactorial(ByRef n As Integer)
Dim product As Integer = 1
Do While n > 1
product = product * n
n = n - 1
Loop
n = product
End Sub
Private Sub btnFact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFact.Click
Dim num As Integer = Val(tbNum.Text)
GetFactorial(num)
MessageBox.Show(num)
End Sub
Private Sub btnCombos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCombos.Click
' The number of combinations is calculated using
' the following formula: N! / ( R! * (N-R)! )
Dim n As Integer = Val(tbN.Text)
Dim r As Integer = Val(tbR.Text)
Dim nMinusR As Integer = n - r
GetFactorial(n)
GetFactorial(r)
GetFactorial(nMinusR)
Dim numCombinations As Integer
numCombinations = n / (r * nMinusR)
MessageBox.Show(numCombinations)
End Sub
End Class