Option Explicit
Private Sub cmdIsPrime_Click() If txtNumber.Text = "1" Then MsgBox _ "1 cannot be tested.", vbOKOnly, "Error": Exit Sub MsgBox IsPrime(txtNumber.Text) End Sub Public Function IsPrime(Number) As Boolean Dim CountUp As Long CountUp = 2 Do Until CountUp = Number If (InStr(1, CStr((Number / CountUp)), ".")) = 0 Then IsPrime = False: Exit Function Else IsPrime = True End If CountUp = CountUp + 1 Loop End Function |