VB 求大神指教···这个程序的代码···
2个回答
展开全部
Private Sub C1_Click() '设置计算按钮
Dim n As Integer, max As Integer
DoEvents '防止运算过多造成死机
For n = 1 To 18000
If Isprime(n) = True Then
max = n
End If
Next n
Text1.Text = max
End Sub
Private Function Isprime(a As Integer) As Boolean '定义素数判断函数
Dim Flag As Boolean, b%
Flag = True
b% = 2
Do While b% <= Int(a / 2) And Flag
If Int(a / b%) = a / b% Then
Flag = False
Else
b% = b% + 1
End If
Loop
Isprime = Flag
End Function
Private Sub C2_Click() '设置存盘按钮
Open "E:\shixi\out1.txt" For Append As #1
Print #1, Text1.Text
Close 1
MsgBox "保存成功!", vbOKOnly, "提示"
End Sub
代码部分大概就这样了,运算结果的话是17989,有啥问题再问我吧,希望对你有帮助~
Dim n As Integer, max As Integer
DoEvents '防止运算过多造成死机
For n = 1 To 18000
If Isprime(n) = True Then
max = n
End If
Next n
Text1.Text = max
End Sub
Private Function Isprime(a As Integer) As Boolean '定义素数判断函数
Dim Flag As Boolean, b%
Flag = True
b% = 2
Do While b% <= Int(a / 2) And Flag
If Int(a / b%) = a / b% Then
Flag = False
Else
b% = b% + 1
End If
Loop
Isprime = Flag
End Function
Private Sub C2_Click() '设置存盘按钮
Open "E:\shixi\out1.txt" For Append As #1
Print #1, Text1.Text
Close 1
MsgBox "保存成功!", vbOKOnly, "提示"
End Sub
代码部分大概就这样了,运算结果的话是17989,有啥问题再问我吧,希望对你有帮助~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询