比如说我想让对方输入IP  
没有"."就算是非法操作
如何实现
谢谢

解决方案 »

  1.   

    dim j,i as long
    for j=1to len(text1.text)  'text1.text中输入IP地址
    if asc(mid(text1.text,j,1))=46 then
    i=i+1
    end if
    next
    if i<>3 then          '判断输入IP中是否有3个"."号,如果少于或者大于3个,提示错误信息
    msgbox "请正确输入IP地址"
    else
    .....
      

  2.   

    Option ExplicitPrivate Sub Command1_Click()
        Debug.Print isip("1")
        Debug.Print isip("1.2")
        Debug.Print isip("1.2.3")
        Debug.Print isip("1.2.3.4")
        Debug.Print isip("1.2.3.5")
        Debug.Print isip("1.2.3..6")
    End SubPrivate Function isip(ByVal ip As String) As Boolean
        Dim i As Long
        Dim j As Long
        Dim count As Long
        
        Dim ips(0 To 20) As String
        
        i = 1
        
        Do
            j = InStr(i, ip, ".")
            If j = 0 Then
                Exit Do
            End If
            ips(count) = Mid(ip, i, j - i)
            count = count + 1
            i = j + 1
            If count > 5 Then
                isip = False
                Exit Function
            End If
        Loop While j
        
        If count <> 3 Then
            isip = False
            Exit Function
        End If    For i = 0 To count - 1
            If Len(Trim(ips(i))) = 0 Then
                isip = False
                Exit Function
            End If
            If Val(ips(i)) < 0 Or Val(ips(i)) > 255 Then
                isip = False
                Exit Function
            End If
        Next i
        
        isip = True
    End Function
      

  3.   

    Private Function isip(ByVal ip As String) As Boolean
        Dim i As Long
        Dim j As Long
        Dim count As Long
        
        Dim ips(0 To 20) As String
        
        i = 1
        
        Do
            j = InStr(i, ip, ".")
            If j = 0 Then
                ips(count) = Mid(ip, i)
                count = count + 1
                Exit Do
            End If
            ips(count) = Mid(ip, i, j - i)
            count = count + 1
            i = j + 1
            If count > 5 Then
                isip = False
                Exit Function
            End If
        Loop While j
        
        If count <> 4 Then
            isip = False
            Exit Function
        End If    For i = 0 To count - 1
            If Len(Trim(ips(i))) = 0 Then
                isip = False
                Exit Function
            End If
            If Val(ips(i)) < 0 Or Val(ips(i)) > 255 Then
                isip = False
                Exit Function
            End If
        Next i
        
        isip = True
    End Function
      

  4.   

    假设TextBox1接受用户输入。
    Dim ArrayList
    ArrayList=split(textbox1.text,".",-1,vbTextCompare)
    若Ubound(ArrayList)小于3,就不是有限IP