注册 登录
编程论坛 VB6论坛

MSGBOX strip改成文本框显示,如何修改

rogersgb 发布于 2016-02-03 15:11, 2085 次点击
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long

'获取IP地址
Private Const MAX_IP = 255

Private Type IPINFO
            dwAddr   As Long    'IP地址
            dwIndex   As Long
            dwMask   As Long    '掩码
            dwBCastAddr   As Long    '广播地址
            dwReasmSize   As Long
            unused1   As Integer
            unused2   As Integer
End Type


Private Type MIB_IPADDRTABLE
            dEntrys   As Long
            mIPInfo(MAX_IP)   As IPINFO
End Type
Private Type IP_Array
            mBuffer   As MIB_IPADDRTABLE
            BufferLen   As Long
End Type
Dim strIP     As String


Private Function ConvertAddressToString(longAddr As Long) As String
    Dim myByte(3)     As Byte
    Dim Cnt     As Long
    CopyMemory myByte(0), longAddr, 4
    For Cnt = 0 To 3
        ConvertAddressToString = ConvertAddressToString + CStr(myByte(Cnt)) + "."
    Next Cnt
    ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
End Function
Public Sub Start()

    Dim Ret     As Long, Tel       As Long
    Dim bBytes()     As Byte
    Dim Listing     As MIB_IPADDRTABLE

    On Error GoTo END1
    GetIpAddrTable ByVal 0&, Ret, True

    If Ret <= 0 Then Exit Sub

    ReDim bBytes(0 To Ret - 1) As Byte

    GetIpAddrTable bBytes(0), Ret, False
    CopyMemory Listing.dEntrys, bBytes(0), 4

    For Tel = 0 To Listing.dEntrys - 1
 CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
If InStr(1, ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr), "10.26") > 0 Or InStr(1, ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr), "10.6") > 0 Or InStr(1, ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr), "10.86") > 0 Then
 strIP = ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr)
        End If
    Next
    MsgBox strIP
    Exit Sub
END1:
    MsgBox "ERROR"
   
End Sub


4 回复
#2
风吹过b2016-02-03 15:40
    MsgBox strIP

这句是显示,
你放个 文本框 ,然后把这个值给文本框
如 text1.text=strIP
就是了。
--------------
白天写错了符号了。

[此贴子已经被作者于2016-2-3 21:18编辑过]

#3
rogersgb2016-02-03 15:46
回复 2楼 风吹过b
试过,不行啊
#4
rogersgb2016-02-03 15:54
回复 2楼 风吹过b
msgbox strIP改成下面执行不了
Shell "route -p add 100.0.0.0 mask 255.255.255.0" & strIP
#5
rogersgb2016-02-03 16:27
回复 4楼 rogersgb
可以了,少了一个空格
1