Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Question 1

Status
Not open for further replies.

Nitrous270

Technical User
Jul 27, 2002
67
0
0
US
I'm pulling in a IPAddress using WMI and then I'd like to convert the IP Octets into an array. I'm having trouble creating the array. I'm probably missing something simple but I can't seem to figure this out.


Can someone explain why this doesn't work

strIPAddress="192.168.0.1"
arrIP= Array(Replace(strIPAddress, ".", ","))
wscript.echo arrIP(2)

ECHO 192.168.0.1

However this does work,

arrIP=Array(192,168,0,1)
wscript.echo arrIP(2)

ECHO 0



Here is the whole code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For Each objAdapter In colAdapters
strIPAddress = objAdapter.IPAddress(0)
msgbox strIPAddress
Next

arrIP= Array(Replace(strIPAddress, ".", ","))
wscript.echo arrIP(2)

Set colAdapters = Nothing
Set objWMIService = Nothing


Thanks for the help,
Ryan
 
Try this:
strIPAddress = "192.168.0.1"
arrIP = Split(strIPAddress, ".")


This should return the following values
arrIP(0) = "192"
arrIP(1) = "168"
arrIP(2) = "0"
arrIP(3) = "1
 
That did the trick. I knew there had to be something simple.

Thanks,
Skie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top