Private Sub Command1_Click()
Dim n As Long
n = Val(InputBox("请输入要判断的大于0的数:"))
If n < 1 Then MsgBox "你输入的是0": Exit Sub
If zhi(n) Then MsgBox "是素数" Else MsgBox "不是素数"
End Sub
Private Function zhi(x As Long) As Boolean
Dim b As Single, i As Long, f As Long
For i = 2 To x - 1
If x Mod i = 0 Then
f = 1: Exit For
End If
Next
If f = 1 Then zhi = False Else zhi = True
End Function