How to verify a prime number in VB

See this post in: Chinese Version or French Version

Private Sub Command1_Click()
 r = InputBox(“Enter a number please”) ‘ Enter a number to verify
 For i = 2 To r
   If Val(r) Mod i = 0 And i <> Val(r) Then ‘ this phase give a condition which is not a prime number
    MsgBox (“The numbered you entered is not a prime number”)
    Exit Sub
   End If
 Next i
 MsgBox (“The numbered you entered is not a prime number”)
End Sub

Continue reading

↑ Back to top