看板 Visual_Basic 關於我們 聯絡資訊
Public Sub ShowPrime() MsgBox "1到" & 100 & "之間的質數有:[" & EnumPrime(100) & "]", _ vbInformation End Sub Public Function IsPrime(ByVal number As Long) As Boolean If number <= 1 Then IsPrime = False: Exit Function If number = 2 Or number = 3 Or number = 5 Or number = 7 Then IsPrime = True: Exit Function End If Dim i As Long For i = 2 To Sqr(number) If number Mod i = 0 Then IsPrime = False: Exit Function Next IsPrime = True End Function Public Function EnumPrime(ByVal n As Long) As String Dim i As Long, count As Long, s As String For i = 1 To n If IsPrime(i) Then If s <> "" Then s = s & "," s = s & i End If Next EnumPrime = s End Function -- ▃▅▇▆▄ ▆▂▃ ` 逝去感如何能留住,半點遺留殊不易,██▅▇▄▃ ▇▃▂" . █████████▃i ▁▄▇ 更多悽悽慘慘的遭遇………██▆▃ █▅▆▃ˍ▄* ▂█▄▇▅▂. 我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.194.224.174
mick1031:請問一下..Isprime是VBA方法嗎..為什麼我用VBA說明找不到 06/24 16:21
fumizuki:我都在下面列出IsPrime了 怎麼會是VBA提供的@@ 06/24 18:10
mick1031:所以..不懂..IsPrime是什麼= =?另一種語言..?抱歉....... 06/24 21:01
FantasyRyu:樓上 Public Function IsPrime =_=a 06/24 22:23
FantasyRyu:哦哦,我猜他還在練寫console,沒學到自定函數 06/24 22:25