当前位置:编程学习 > VB >>

求VB大神帮忙

Private Sub Command1_Click() Dim A As Integer Dim b As Integer A = Text1.Text b = Text2.Text Dim i As Integer For i = A To b If prime(i) = True Then List1.AddItem "本区间无幻影素数" Next i ElseIf prime(re_num(i)) = True Then List1.AddItem "本区间无幻影素数" Next i Else List1.AddItem "幻影素数对" & vbcrlf & i+"与"+re_num(i) Next i End If End Sub Private Sub Command2_Click() Text1.Text = "" Text2.Text = "" Text1.SetFocus List1.Cls End Sub Public Function prime(x As Integer) As Boolean Dim i As Integer prime = False For i = 1 To Sqr(x) If x Mod i = 0 Then prime = True Exit For End If Next i End Function Public Function re_num(N) As Integer Do re_num = re_num * 10 + (N Mod 10) N = N \ 10 Loop While N > 0 End Function 哪里错了,怎么老不对
答案:已经通过试验 ^_^
Private Sub Command1_Click()
Dim A As Integer
Dim b As Integer
A = Text1.Text
b = Text2.Text
Dim i As Integer
For i = A To b
    If prime(i) = True Then
        List1.AddItem "本区间无幻影素数"
'Next i
    ElseIf prime(re_num(i)) = True Then
        List1.AddItem "本区间无幻影素数"
   '     Next i
    Else
        List1.AddItem "幻影素数对" & vbCrLf & i & "与" & re_num(i)
       
    End If
 Next i
End Sub

Private Sub Command2_Click()
    Text1.Text = ""
    Text2.Text = ""
    Text1.SetFocus
    List1.Clear
End Sub

Public Function prime(ByVal x As Integer) As Boolean
    Dim i As Integer
    prime = False
    For i = 2 To Sqr(x)'如果为1恒为true 
        If x Mod i = 0 Then
            prime = True
        Exit For
        End If
    Next i
End Function

Public Function re_num(ByVal N) As Integer
Do
   re_num = re_num * 10 + (N Mod 10)
   N = N \ 10
Loop While N > 0
End Function
其他:Private Sub Command1_Click()  ‘判断
    Dim A%, B%, i%
    A = Text1.Text
    B = Text2.Text
    For i = A To B
        If prime(i) = True Then
            List1.AddItem i & "不是素数"
        ElseIf prime(re_num(i)) = True Then
            List1.AddItem i & "不是幻影素数"
        Else
            List1.AddItem "幻影素数对" & vbCrLf & i + "与" + re_num(i)
        End If
    Next i
End Sub

Private Sub Command2_Click()  '清空
    Text1.Text = ""
    Text2.Text = ""
    Text1.SetFocus
    List1.Clear    '清空
End Sub

Public Function prime(x As Integer) As Boolean
    Dim i As Integer
    prime = False
    For i = 1 To Sqr(x)
        If x Mod i = 0 Then
            prime = True
        Exit For
        End If
    Next i
End Function

Public Function re_num(N) As Integer
    Do
        re_num = re_num * 10 + (N Mod 10)
        N = N \ 10
   Loop While N > 0
End Function

上一个:VB程序,帮忙解释一下啥意思,越详细越好
下一个:vb的paintpicture方法

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,