ip="192.168.1.1"
Print Left(ip, 3)
'或是
Print Mid(ip, 1, 3)
最准确的方法应该是:
Print IIf(InStr(ip, ".") > 1, Left(ip, InStr(ip, ".") - 1), "")
往窗体上添加一个winsock控件,需要从工程中添加
工程-部件-Microsoft Winsock Control6.0
程序运行时,单击窗体就把本机IP的前三段打印到窗体上,代码如下:
Private Sub Form_Click()
Dim a As String
a = Winsock1.LocalIP
Do While Right(a, 1) <> "."
a = Mid(a, 1, Len(a) - 1)
Loop
Print Mid(a, 1, Len(a) - 1)
End Sub