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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if then statements 1

Status
Not open for further replies.

saw164

Technical User
Jan 17, 2006
218
US
Hi, I hope somebody can help. What I am doing is running ipconfig saving the output to a text file, then writing the information into an array, and then I am pulling out 1 peace of that information and using it as the variable branchvar1. Now problem I am having is when I am trying to compare that variable to an IP address. here is what it looks like:

Set sh = CreateObject("WScript.Shell")
Workfile = "c:\ipconfig.txt"
sh.run "%comspec% /c ipconfig > " & Workfile, 0, True
sh.run "ipconfig /batch" ,0,true

set objfso = createobject("Scripting.FileSystemObject")
set objtextfile = objfso_OpenTextFile(workfile, ForReading)

do until objtextfile.AtEndOfStream
strnextline = objtextfile.ReadLine
if instr(strnextline, searchstring)then
redim preserve arrip(intsize)
arrip(intsize) = strnextline
intsize = intsize + 1
end if
loop
arrdg = split(arrip(4), ":")

branchvar1 = arrdg(1)

now when i try and write the

if branchvar1 = "172.16.172.1" then
brancharray(1,0) = "scott"
wscript.echo brancharray(1,0)
end if

nothing happens...i know that branchvar1 = 172.16.172.1, because when I wscript.echo branchvar1 that is what it gives me. I am using the wscript.echo brancharray(1,0) to make sure it is reading the if statement. when i test in onscript editor on the output nothing happens it just says completed


Scott

"Global Warming is caused by the sun" - Anonymous

 
What does this return?

Code:
if [COLOR=red]Trim([/color]branchvar1[COLOR=red])[/color] = "172.16.172.1" then
   brancharray(1,0) = "scott"
   wscript.echo brancharray(1,0)
[COLOR=red]else
   wsript.echo "Failed, Trim(branchvar1) = " & Trim(branchvar1)[/color]
end if
 
replyed with
Failed, Trim(branchvar1) = 172.16.172.1

Scott

"Global Warming is caused by the sun" - Anonymous

 
Well I'll be... There's an extra carriage return left at the end of each line, that's why the IF fails. I would have thought that .ReadLine would removed that, but apparently not???

Try this, after you read each line:

Code:
strnextline = objtextfile.ReadLine
[COLOR=red]strnextline = Replace(strnextline, vbCr, "")[/color]
 
Thank you so much, That took care if it. when i echo out the branchvar1, i saw the extra carriage return, so i tried to place it in the " " but that didn't work, i didn't know about the Replace(strnextline, vbCr, "") command, thank you once again.

Scott

"Global Warming is caused by the sun" - Anonymous

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top