请求高人指点我的白痴VB问题呀!!! Option Explicit Private Sub Command1_Click() Dim y As Integer, m
在文本1中输入大于10的偶数,找出靠10最近的素数(左右两边靠10最近的)OptionExplicitPrivateSubCommand1_Click()DimyAsIn...
在文本1中输入大于10的偶数,找出靠10最近的素数(左右两边靠10最近的)
Option Explicit
Private Sub Command1_Click()
Dim y As Integer, m As Integer, k As Integer, i As Integer, n As Integer
Dim min As Integer, max As Integer, prime As Boolean
y = Text1.Text
For i = y To 10 Step -1
Call prime(i)
If prime = True Then m = i
Exit For
Next i
Do
k = y + 1
Call prime(k)
If prime = True Then
Exit Do
Loop
min = k - y
max = y - m
If min < max Then
Text2.Text = "k"
Else: Text2.Text = "m"
End If
End Sub
Private Function prime(a As Integer) As Boolean
Dim j As Integer
For j = 2 To a - 1
If a Mod j = 0 Then Exit Function
Next i
prime = True
End Function
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
End Sub
程序运行时总是说 call prime(i) 这个地方缺少子程序,函数或者属性 是怎么回事呀 展开
Option Explicit
Private Sub Command1_Click()
Dim y As Integer, m As Integer, k As Integer, i As Integer, n As Integer
Dim min As Integer, max As Integer, prime As Boolean
y = Text1.Text
For i = y To 10 Step -1
Call prime(i)
If prime = True Then m = i
Exit For
Next i
Do
k = y + 1
Call prime(k)
If prime = True Then
Exit Do
Loop
min = k - y
max = y - m
If min < max Then
Text2.Text = "k"
Else: Text2.Text = "m"
End If
End Sub
Private Function prime(a As Integer) As Boolean
Dim j As Integer
For j = 2 To a - 1
If a Mod j = 0 Then Exit Function
Next i
prime = True
End Function
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
End Sub
程序运行时总是说 call prime(i) 这个地方缺少子程序,函数或者属性 是怎么回事呀 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询