I am working on XI R2 . I wanted to develop a macro that can capture the local IP address. For that, I am supposed to add Winsock control in a foprm. But when I click on Tools -> Additional Controls , nothing appears. When I right click on the Toolbox and click on Additional COntrols, then nothing appears. What can be the reason? Please help
We use the following to return a local machine’s IP Address…
You can execute the TestIp() function to test the process.
Private Declare Function GetIpAddrTable_API Lib "IpHlpApi" Alias "GetIpAddrTable" (pIPAddrTable As Any, pdwSize As Long, ByVal bOrder As Long) As Long
Public Sub TestIp()
MsgBox ReturnIpAddress
End Sub
Function ReturnIpAddress()
Dim IpAddrs
Dim i As Integer
Dim sIpAddress As String
IpAddrs = GetIpAddrTable
sIpAddress = IpAddrs(0)
ReturnIpAddress = sIpAddress
End Function
Public Function GetIpAddrTable()
Dim Buf(0 To 511) As Byte
Dim BufSize As Long: BufSize = UBound(Buf) + 1
Dim rc As Long
Dim i As Integer
rc = GetIpAddrTable_API(Buf(0), BufSize, 1)
If rc <> 0 Then Err.Raise vbObjectError, , "GetIpAddrTable failed with return value " & rc
Dim NrOfEntries As Integer: NrOfEntries = Buf(1) * 256 + Buf(0)
If NrOfEntries = 0 Then GetIpAddrTable = Array(): Exit Function
ReDim IpAddrs(0 To NrOfEntries - 1) As String
For i = 0 To 0 'NrOfEntries - 1
Dim j As Integer, s As String: s = ""
For j = 0 To 3: s = s & IIf(j > 0, ".", "") & Buf(4 + i * 24 + j): Next
IpAddrs(i) = s
Next
GetIpAddrTable = IpAddrs
End Function