Option Explicit
Private Sub Form_click()'窗口单击事件
Dim i As Integer
For i = 100 To 300 '生成100到300的所有数值
If isPrime(i) = 0 Then Print i '调用素数判断函数判断当前数是否为素数
Next i
End Sub
Function isPrime(X As Integer) As Integer
Dim i As Integer
If X <= 1 Then isPrime = -1 '素数范围>=2
For i = 2 To X - 1
If X Mod i = 0 Then
isPrime = 1 '合数
Exit For
Else
isPrime = 0 '素数
End If
Next i
End Function