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

Incrementing 1

Status
Not open for further replies.

NetNodeMan

Technical User
Mar 30, 2005
65
IE
I'm trying to get my code to increment but the only thing incrementing seems to be the number of times I'm banging my head off the table here:


Sub objIE_NavigateError(pDisp,URL,TargetFrameName,StatusCode,Cancel)

internetError = internetError + 1
wshell.popup "Failure when loading"
createobject("wscript.shell").run "WebTest.bat"

End Sub


if internetError <>0 and internetError Mod 3 = 0 then

wshell.popup "Failure when loading more than 3 times"
createobject("wscript.shell").run "WebTracker.bat"

end if

I have my code laid out so it writes internetError to a log. internetError is set as a dim and equalled to 0 elsewhere in my code BUT:

internetError always = 0 when printed to the log. Can anyone tell me where I'm going wrong? Code is welcomed :)
 
No way to determine the problem from what posted, but apparently you need to call the sub somewhere and internetError is counting the number it is being called. The internetError has to have global scope.
 
In layman terms tjusi? Apologies but that doesn't mean much to me.
 
As a way to detect, how many time do you see the popup?
[tt]> wshell.popup "Failure when loading"[/tt]
 
Well what happens is it accesses the page and if an error it will send a popup. It then closes the script and opens a new one so the popup could appear as many times as it wants. However, the internetError is still always 1 in the log file.
 
If somehow the page errors out it closes the script itself and opens a new one, the variable internalError would be re-initiated to 0. And then, the sub is called, internetError becomes 1. In the meantime after, log records internalError which sure is 1. After recording, the script closes itself and opens anew of itself and then internalError is again be re-initiated to 1. Then the story repeats itself.
 
Ah - so it does. Good thinking, and how do I get around this?
 
The better way is to rethink over the plan. As a quick solution, the idea is to persist the internalError to the next instance of the same script. A way is to pass the script with an argument which is the internalError itself.
 
tjusi, you're posts are inspiring but I'm afraid you are giving me FAR too much credit here.

How exactly would I do that?
 
Make a vbs file and run it by double=click.
[tt]
dim internalError
if wscript.arguments.count=0 then
internalError=0
else
internalError=cint(wscript.arguments.item(0))
end if

fspec=wscript.scriptfullname
wscript.echo "This file is : " & fspec & vbcrlf & "internalError = " & internalError

wscript.sleep 2000 'wait two second for visual comfort
if (internalError+1) mod 3<>0 then
createobject("wscript.shell").run fspec & " " & internalError+1,1,false
else
wscript.echo "The script will not repeat itself anymore. Goodbye!"
end if
wscript.quit
[/tt]
 
tjusi,

That means nothing to me. Apologies. Complete newbie here. If too much time is wasted then never mind.
 
That's okay. Maybe I should donate the star to charity.
 
Perhaps. Thanks anyway for replying. Is there no way of doing this within the code?
 
You will need to post more of your code.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
What I want to happen is that a mail is sent after 5 errors. Problem is, my errors never reach 5 because when an error occurs the command shell closes and reopens, setting ieErr back to 0. (thanks tjusi)

What I need:

Could somebody help edit my code so that the count of ieErr can either be passed to the next command shell or that the count can be incrememnted without the command shell closing & reopening?

I really need code on this because it has driven me absolutely around the bend. My ieErr is not incrementing and I also need something to happen when it reaches 5 errors (and once the mail is sent or a test OK to revert to 0 errors)

Thanks in advance

Option explicit

Sould I dim ieErr here?



Sub objIE_NavigateError(pDisp,URL,TargetFrameName,StatusCode,Cancel)



wscript.echo now() & " Website Could Not Be Contacted"
wshshell.run "c:\alert.bat"
logfile.writeline now() & " Please Investigate."
wshshell.popup "Document failed to load."
ieErr = ieErr + 1
logfile.writeline now() & ieErr
logfile.close
createobject("wscript.shell").run "test.bat"
ie.quit



End Sub


Function Wait()
sError = 1
Do while IE.busy
wscript.sleep 1000
sError = sError + 1
Loop
if sError > 20 then
exit Function
end if
dState = IE.document.readystate

while (dState <> "complete" and sError < 20)
Wscript.sleep 1000
dState = IE.document.readystate
sError = sError + 1
wend

' *************IF INTERNET EXPLORER PAGE FAILS TO OPEN

if ieErr <> 0 and ieErr Mod 5 = 0 then 'navigation error

logfile.writeline now() & ieErr
wshshell.run "c:\sendmail.bat"

logfile.close
createobject("wscript.shell").run "test.bat"
ie.quit




end if
end function



'**************CREATE LOGFILE AND AMEND/APPEND

dim wshshell, fso , slog , logfile
dim ieErr



set wshshell=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")


slog = "c:\log\" & Right("0" & Day(Date), 2) & Right("0" & Month(Date), 2) & Year(Date) & ".log"






................Code code code code..............



if sError <= 60 then
wscript.echo now() & " Test OK"
logfile.writeline now() & " Test OK"
counterrors = counterrors + 1
logfile.close
ie.quit
exit do

else

wscript.echo now() & " Test FAILURE"
logfile.writeline now() & " Test FAILURE"
wshshell.run "c:\alert.bat"
logfile.writeline now() & " Please Investigate."
wshshell.popup " Please Investigate",15
createobject("wscript.shell").run "test.bat"
logfile.close
ie.quit

end if
exit do


sLoop2 = "done"
Loop
'Wait for 15 Minutes
Wscript.Sleep 900000

Loop
 
The code you posted won't even compile let alone do what you want. Is this code tht you are really running?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Yep. Sure is. And it does complete the job I need it to do - besides what's missing above.
 
What are alert.bat and test.bat? If you can post them. If one of them call the script itself, you can pass ieErr to the .bat and from the .bat pass it to the vbscript itself again.
 
alert.bat & test.bat are batch files that I call.

test.bat calls the script itself. How do I pass ieErr to test.bat?
 
If test.bat contains nothing else but the line like "wscript.exe thisscript.vbs", then you can get rid of it completely. Read the script I posted above, it is the solution in this direction. (InternalError is your ieErr, the .run line is to replace you line on test.bat.) fspec is the script itself, you do need to have to hard code the name. Read my demo carefully.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top