谢谢,各位

解决方案 »

  1.   

    请使用   MaskEdBox 控件,强制让它是合法格式:MaskEdBox1.Mask ="###.###.###.###"
      

  2.   

    补充一下:MaskEdBox1.Mask = "###.###.###.###"
    MaskEdBox1.PromptChar = " "
      

  3.   

    mask属性设置为:
    ###.###.###.###
      

  4.   

    同上,但是还要进行处理,用STR操作取中间的数字,判断是否小于256,最后才能使用

        Cint(MID(S,0,3))<256
        Cint(MID(S,5,3))<256
        Cint(MID(S,9,3))<256
        Cint(MID(S,13,3))<256
    不过你最好是用查找找索引然后再MID
      

  5.   

    判断是否为合法:Private Sub Command1_Click()
    Dim temp() As String
    Dim bo As Boolean
    bo = Truetemp() = Split(MaskEdBox1.Text, ".")    '四组ip数都存放在temp(0)-temp(3)里,自己可以任意组合成一个有效的string.For i = 0 To 3
      If Val(temp(i)) > 255 Then
         bo = False
      End If
    Next iIf bo = False Then
      MsgBox "不合法"
    Else
      MsgBox "合法"
    End IfEnd Sub
      

  6.   

    VERSION 5.00
    Begin VB.Form FrmMain 
       AutoRedraw      =   -1  'True
       BorderStyle     =   1  'Fixed Single
       Caption         =   "IP&iquest;&Oslash;&frac14;&thorn;&Ntilde;&Yacute;&Ecirc;&frac34;"
       ClientHeight    =   3195
       ClientLeft      =   45
       ClientTop       =   330
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       MaxButton       =   0   'False
       ScaleHeight     =   3195
       ScaleWidth      =   4680
       StartUpPosition =   3  '&acute;°&iquest;&Uacute;&Egrave;±&Ecirc;&iexcl;
       Begin VB.CommandButton CmdSet 
          Caption         =   "&Eacute;è&Ouml;&Atilde;&frac12;á&sup1;&ucirc;"
          Height          =   495
          Left            =   240
          TabIndex        =   2
          Top             =   1500
          Width           =   885
       End
       Begin VB.TextBox Text1 
          Height          =   315
          Left            =   1380
          TabIndex        =   1
          Text            =   "Text1"
          Top             =   960
          Width           =   2595
       End
       Begin VB.CommandButton CmdGet 
          Caption         =   "&Egrave;&iexcl;&micro;&Atilde;&frac12;á&sup1;&ucirc;"
          Height          =   435
          Left            =   210
          TabIndex        =   0
          Top             =   870
          Width           =   885
       End
    End
    Attribute VB_Name = "FrmMain"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option ExplicitPrivate Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function INITCOMMONCONTROLSEX Lib "comctl32.dll" Alias "InitCommonControlsEx" (ByRef TLPINITCOMMONCONTROLSEX As INITCOMMONCONTROLSEX) As Long
    Private Type INITCOMMONCONTROLSEX
        dwSize As Long 'size of this structure
        dwICC As Long 'flags indicating which classes to be initialized
    End Type
    Private Const ICC_INTERNET_CLASSES As Long = &H800Private Const WS_CHILD As Long = &H40000000
    Private Const WS_GROUP As Long = &H20000
    Private Const WS_TABSTOP As Long = &H10000
    Private Const WS_VISIBLE As Long = &H10000000Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Const WM_SETFONT As Long = &H30
    Private Const WM_GETFONT As Long = &H31Private Const WM_USER As Long = &H400
    Private Const IPM_CLEARADDRESS As Long = (WM_USER + 100)
    Private Const IPM_SETADDRESS   As Long = (WM_USER + 101)
    Private Const IPM_GETADDRESS   As Long = (WM_USER + 102)
    Private Const IPM_SETRANGE     As Long = (WM_USER + 103)
    Private Const IPM_SETFOCUS     As Long = (WM_USER + 104)
    Private Const IPM_ISBLANK      As Long = (WM_USER + 105)'#define FIRST_IPADDRESS(x)  ((x>>24) & 0xff)
    '#define SECOND_IPADDRESS(x) ((x>>16) & 0xff)
    '#define THIRD_IPADDRESS(x)  ((x>>8) & 0xff)
    '#define FOURTH_IPADDRESS(x) (x & 0xff)
    '#define MAKEIPRANGE(low, high)    ((LPARAM)(WORD)(((BYTE)(high) << 8) + (BYTE)(low)))
    '#define MAKEIPADDRESS(b1,b2,b3,b4)  ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
    Private IP1 As LongPublic Function FIRST_IPADDRESS(ByVal x As Long) As Byte
        FIRST_IPADDRESS = ((x And &H7F000000) \ &H1000000) Or (((x And &H80000000) <> 0) And &H80)
    End FunctionPublic Function SECOND_IPADDRESS(ByVal x As Long) As Byte
        SECOND_IPADDRESS = (x And &HFF0000) \ &H10000
    End FunctionPublic Function THIRD_IPADDRESS(ByVal x As Long) As Byte
        THIRD_IPADDRESS = (x And &HFF00&) \ &H100
    End FunctionPublic Function FOURTH_IPADDRESS(ByVal x As Long) As Byte
        FOURTH_IPADDRESS = x And &HFF
    End FunctionPublic Function MAKEIPRANGE(ByVal low As Byte, ByVal high As Byte) As Long
        MAKEIPRANGE = high * &H100& Or low
    End FunctionPublic Function MAKEIPADDRESS(ByVal b1 As Byte, ByVal b2 As Byte, ByVal b3 As Byte, ByVal b4 As Byte) As Long
        MAKEIPADDRESS = ((b1 And &H7F) * &H1000000 Or (b1 And &H80) <> 0 And &H80000000) Or (b2 * &H10000) Or (b3 * &H100&) Or (b4)
    End FunctionPrivate Sub CmdGet_Click()
        Dim TempLng As Long
        
        SendMessage IP1, IPM_GETADDRESS, 0, TempLng
        
        Text1.Text = FIRST_IPADDRESS(TempLng) & "," & SECOND_IPADDRESS(TempLng) & "," & THIRD_IPADDRESS(TempLng) & "," & FOURTH_IPADDRESS(TempLng)
        
    End SubPrivate Sub CmdSet_Click()
        SendMessage IP1, IPM_SETADDRESS, 0, ByVal MAKEIPADDRESS(1, 2, 3, 4)
        
    End SubPrivate Sub Form_Load()
        Dim CommCtrl As INITCOMMONCONTROLSEX
        
        CommCtrl.dwSize = Len(CommCtrl)
        CommCtrl.dwICC = ICC_INTERNET_CLASSES
        
        If INITCOMMONCONTROLSEX(CommCtrl) Then
            IP1 = CreateWindowEx(0, "SysIPAddress32", "IPADDR1", _
                    WS_CHILD Or WS_TABSTOP Or WS_GROUP Or WS_VISIBLE, _
                    (Me.ScaleX(Me.ScaleWidth, Me.ScaleMode, vbPixels) - 128) \ 2, 10, 128, 20, _
                    Me.hwnd, 0, App.hInstance, ByVal 0&)
            If IP1 Then
                '&frac12;&laquo;IP&iquest;&Oslash;&frac14;&thorn;&micro;&Auml;×&Ouml;&Igrave;&aring;&Eacute;è&Ouml;&Atilde;&micro;&Auml;&cedil;ù&acute;°&Igrave;&aring;&Ograve;&raquo;&Ntilde;ù &Oacute;&Atilde;&Euml;&Icirc;&Igrave;&aring;
                SendMessage IP1, WM_SETFONT, SendMessage(Me.hwnd, WM_GETFONT, 0, ByVal 0&), ByVal 0&
            Else
                MsgBox "&sup2;&raquo;&Auml;&Uuml;&acute;&acute;&frac12;¨&iquest;&Oslash;&frac14;&thorn;", vbCritical, "&acute;í&Icirc;ó&pound;&iexcl;"
                End
            End If
            
        Else
            MsgBox "&sup2;&raquo;&Auml;&Uuml;&acute;&acute;&frac12;¨&iquest;&Oslash;&frac14;&thorn;", vbCritical, "&acute;í&Icirc;ó&pound;&iexcl;"
            End
        End If
        
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        DestroyWindow IP1
        
    End Sub
      

  7.   

    PING一下TEXT里面的IP,如果能PING通就是合法,岂不更简单?
      

  8.   

    PING一下就对了,既合法又在线
      

  9.   

    我也UP,最好让TEXT只能输入数字
      

  10.   

    GetWindowPos(阿汪)  在keypress事件里处理,判断键值的ascii码值大小来限制只输入数字.dustwoo(尘)  动动脑筋,这些都是些不是问题的问题,总找现成的,那你还写什么程序啊??