原始碼:http://down.gogobox.com.tw/t2329175/vq2m2
Dim key As Long, Target As Long, Rear As Long, i As Long

Private Sub Bu1_Click()
Dim tmp As Long
Dim Num(20) As Long, Numx(20) As Long
La1.Caption = "" '清空結果
DoEvents '釋放控制權
Target = Val(TB1.Text)
If Target > 0 And Target <= 10000000 Then
La2.Visible = True '提示計算中
Rear = -1
tmp = Target \ 2
For i = 2 To tmp
If NumCheck(Target) = True And Target > 1 Then
Rear = Rear + 1
Num(Rear) = Target
Numx(Rear) = Numx(Rear) + 1
Exit For
End If
If i > 2 And Val(Mid(Str(i), Len(Str(i)), 1)) Mod 2 = 0 Then i = i + 1
If Target Mod i = 0 Then
Rear = Rear + 1
Num(Rear) = i
Do While Target Mod i = 0
Target = Target \ i
Numx(Rear) = Numx(Rear) + 1
Loop
End If
Next
La2.Visible = False '結束提示
DoEvents '釋放控制權
For i = 0 To Rear
If Numx(i) <> 1 Then
La1.Caption = La1.Caption & Str(Num(i)) & " ^" & Str(Numx(i)) & " *"
Else
La1.Caption = La1.Caption & Str(Num(i)) & " *"
End If
Next
La1.Caption = Mid(La1.Caption, 1, Len(La1.Caption) - 1)
Else
MsgBox "超出範圍", vbExclamation, "白目喔!"
End If
End Sub

Public Function NumCheck(ByVal key As Long) As Boolean
NumCheck = True
Dim tmp As Long
tmp = key \ 2
Dim i As Long
For i = 2 To tmp
If key Mod i = 0 Then
NumCheck = False
Exit Function
End If
Next
End Function



創作者介紹
創作者 讓地獄深紅的天亮 的頭像
讓地獄深紅的天亮

!壞人必需做好事!

讓地獄深紅的天亮 發表在 痞客邦 留言(0) 人氣()