又要麻煩各位了,我們老師又出題給我...
如果我們已經知道這個數"不是質數",那要如何列出他的因數於MsgBox上???
我們老師有提示 re = i,但我不知道怎麼PO出來...
Private Function Math(ByVal Number As Integer) As Byte
Dim i As Integer
If Number <= 1 Then
Math = 3
Exit Function
End If
If Number = 2 Then
Math = 1
End If
For i = 2 To Number / 2
If Number Mod i = 0 Then
Math = 2
Exit Function
End If
Next i
Math = 1
End Function
還有這裡三個 If 要如何改成 ElseIf 呢???
小弟有嘗試改過,不過就是有問題...
Private Sub Command1_Click()
On Error GoTo HERE
任意數 = InputBox("請入一個數", "檢查質數")
Select Case Math(任意數)
Case 1
MsgBox "是質數"
Case 2
MsgBox "不是質數"
Case 3
MsgBox "無意義"
End Select
Exit Sub
HERE:
MsgBox "錯誤"
End Sub