I understand how the split function works but for some reason the results are not working in my DO UNTIL loop. What the code does below is ping a subnet via a range that the user puts into an inputbox like 1-254 I use split to split the results into an array which is assigned to rRange(0) and rRange(1) I successfully get the range in each array entity but when my do loop runs it does not recognize the upper range rRange(1) as a number so the script keeps running. I've tried trim and assigning the arrays index (1) to a variable but still no go. If I hard code a number everything works fine. all that said it does recognize the rRange(0)
Full Script see Red font for where the issue is..
Code:
Dim i
Dim RangeTop
i = rRange(0)
RangeTop = rRange(1)
msgbox RangeTop
DO UNTIL i = RangeTop 'rRange(1) 'if I do a DO UNTIL i = 200 it will work.
i = i + 1
strComputer = sIPAddress & i
msgbox strComputerCode:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, pRet, CheckForTxt, sIPAddress, sRange, rRange
'Get parameters for the IP search
pRet= inputbox("Enter a name and path where you want file saved, i.e... C:\myfile.txt")
sRange = inputbox("Enter a range for last octect i.e... 1-254 or 192-205")
sIPAddress = inputbox("Enter a subnet i.e... 192.168.1 or 10.xxx.xxx." & _
vbcrlf & " Make sure to leave last octect blank" )
'Grab the range of last octect to search on
rRange = split(sRange,"-")
'Make sure there is a "." at the end of subnet
checkForDot = Right(sIPAddress,1)
if CheckForDot <> "." then
sIPAddress = sIPAddress & "."
msgbox sIPAddress
end if
'Checks for .txt extension and add it if not there
CheckForTxt= Right(pRet, 4)
if CheckForTxt <> ".txt" then
ret = msgbox ("No file extension associated with file name Would you like to add .TXT to your file name", vbYesNo)
select case ret
case vbYes
pRet= pRet &".txt"
msgbox pRet
'wscript.quit
case VbNo
pRet=pret
msgbox pRet
'wscript.quit
end select
else
'wscript.quit
end if
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(pRet, ForAppending, True)
Set objWMIService = GetObject("winmgmts:\\" & strComputer)
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim i
Dim RangeTop
i = rRange(0)
RangeTop = rRange(1)
msgbox RangeTop
DO UNTIL i = RangeTop 'rRange(1)
i = i + 1
strComputer = sIPAddress & i
msgbox strComputer
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address = '" & strComputer & "'")
For Each objItem in colItems
If objItem.StatusCode = 0 Then
'WScript.Echo "Reply received. " & strComputer
f.WriteLine "Reply received. " & strComputer
ELSE
f.WriteLine "NO Reply. " & strComputer
End If
Next
LOOP
msgbox "Done"
Call Runprogram("notepad" & pRet, False)
Sub RunProgram(filename, Wait)
Set WshShell = WScript.CreateObject("WScript.Shell")
RetVal = WshShell.Run(filename, 1, Wait)
End Sub