Hi, Not a Vb programmer, trying to get the following working is
proving difficult.

Esentially at the moment the script opens IE on a page and refreshes
periodically, I need it to close the browser at a certain time, if
doesn't seem to do anything with the If mytime = xx.xx then statement
in the while loop. i'm probably doing something glaringly wrong.

I've had a good google but can't find anything... help?

Thanks

DIM mytime
mytime = FormatDateTime(Time(), vbShortTime)

On Error Resume Next

Set objExplorer = CreateObject("InternetExplorer.Application")

objExplorer.Navigate "www.bbc.co.uk"

Wscript.Sleep 5000

Set objDoc = objExplorer.Document

Do While True
Wscript.Sleep 5000
objDoc.Location.Reload(True)
If Err <> 0 Then
Wscript.Quit
End If
If mytime = "09:49" Then
objExplorer.quit
End If
Loop

Re: "If time = xx.xx Then" not working? by Richard

Richard
Mon Jul 07 07:44:32 CDT 2008


<skhudy@hotmail.com> wrote in message
news:7a02ebcd-4bee-43af-87ec-0afea8c010a7@d77g2000hsb.googlegroups.com...
> Hi, Not a Vb programmer, trying to get the following working is
> proving difficult.
>
> Esentially at the moment the script opens IE on a page and refreshes
> periodically, I need it to close the browser at a certain time, if
> doesn't seem to do anything with the If mytime = xx.xx then statement
> in the while loop. i'm probably doing something glaringly wrong.
>
> I've had a good google but can't find anything... help?
>
> Thanks
>
> DIM mytime
> mytime = FormatDateTime(Time(), vbShortTime)
>
> On Error Resume Next
>
> Set objExplorer = CreateObject("InternetExplorer.Application")
>
> objExplorer.Navigate "www.bbc.co.uk"
>
> Wscript.Sleep 5000
>
> Set objDoc = objExplorer.Document
>
> Do While True
> Wscript.Sleep 5000
> objDoc.Location.Reload(True)
> If Err <> 0 Then
> Wscript.Quit
> End If
> If mytime = "09:49" Then
> objExplorer.quit
> End If
> Loop

The mytime variable is assigned a value at the beginning, but this value is
never updated. Move the statement that assigns a value to mytime inside the
Do While loop so it gets updated every 5 seconds.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--



Re: "If time = xx.xx Then" not working? by skhudy

skhudy
Mon Jul 07 09:35:25 CDT 2008

On 7 Jul, 13:44, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> <skh...@hotmail.com> wrote in message
>
> news:7a02ebcd-4bee-43af-87ec-0afea8c010a7@d77g2000hsb.googlegroups.com...
>
>
>
>
>
> > Hi, Not a Vb programmer, trying to get the following working is
> > proving difficult.
>
> > Esentially at the moment the script opens IE on a page and refreshes
> > periodically, I need it to close the browser at a certain time, if
> > doesn't seem to do anything with the If mytime =3D xx.xx then statement
> > in the while loop. i'm probably doing something glaringly wrong.
>
> > I've had a good google but can't find anything... help?
>
> > Thanks
>
> > DIM mytime
> > mytime =3D FormatDateTime(Time(), vbShortTime)
>
> > On Error Resume Next
>
> > Set objExplorer =3D CreateObject("InternetExplorer.Application")
>
> > objExplorer.Navigate "www.bbc.co.uk"
>
> > Wscript.Sleep 5000
>
> > Set objDoc =3D objExplorer.Document
>
> > Do While True
> > =A0 =A0Wscript.Sleep 5000
> > =A0 =A0objDoc.Location.Reload(True)
> > =A0 =A0If Err <> 0 Then
> > =A0 =A0 =A0 =A0Wscript.Quit
> > =A0 =A0End If
> > =A0 =A0If mytime =3D "09:49" Then
> > =A0 =A0 =A0 =A0objExplorer.quit
> > =A0 =A0End If
> > Loop
>
> The mytime variable is assigned a value at the beginning, but this value =
is
> never updated. Move the statement that assigns a value to mytime inside t=
he
> Do While loop so it gets updated every 5 seconds.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --- Hide quoted text -
>
> - Show quoted text -

Doh!! Thanks

Re: "If time = xx.xx Then" not working? by Pegasus

Pegasus
Mon Jul 07 11:20:14 CDT 2008


<skhudy@hotmail.com> wrote in message
news:de2d48e5-941b-4c89-bcc2-7e60d9906a71@x41g2000hsb.googlegroups.com...
On 7 Jul, 13:44, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> <skh...@hotmail.com> wrote in message
>
> news:7a02ebcd-4bee-43af-87ec-0afea8c010a7@d77g2000hsb.googlegroups.com...
>
>
>
>
>
> > Hi, Not a Vb programmer, trying to get the following working is
> > proving difficult.
>
> > Esentially at the moment the script opens IE on a page and refreshes
> > periodically, I need it to close the browser at a certain time, if
> > doesn't seem to do anything with the If mytime = xx.xx then statement
> > in the while loop. i'm probably doing something glaringly wrong.
>
> > I've had a good google but can't find anything... help?
>
> > Thanks
>
> > DIM mytime
> > mytime = FormatDateTime(Time(), vbShortTime)
>
> > On Error Resume Next
>
> > Set objExplorer = CreateObject("InternetExplorer.Application")
>
> > objExplorer.Navigate "www.bbc.co.uk"
>
> > Wscript.Sleep 5000
>
> > Set objDoc = objExplorer.Document
>
> > Do While True
> > Wscript.Sleep 5000
> > objDoc.Location.Reload(True)
> > If Err <> 0 Then
> > Wscript.Quit
> > End If
> > If mytime = "09:49" Then
> > objExplorer.quit
> > End If
> > Loop
>
> The mytime variable is assigned a value at the beginning, but this value
> is
> never updated. Move the statement that assigns a value to mytime inside
> the
> Do While loop so it gets updated every 5 seconds.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --- Hide quoted text -
>
> - Show quoted text -

Doh!! Thanks

====================

Such things are easily overlooked. They are just as easily spotted if you
add some debugging code to your loop, e.g. like so:
Do While True
Wscript.Sleep 5000
wscript.echo "Mytime=" & mytime
objDoc.Location.Reload(True)
If Err <> 0 Then
Wscript.Quit
End If
If mytime = "09:49" Then
objExplorer.quit
End If
Loop



RE: "If time = xx.xx Then" not working? by OldPedant

OldPedant
Mon Jul 07 18:54:14 CDT 2008

Better than formatting the time into a string and then comparing the string
for equals is to use it *AS* a time and do a >= compare.

After all, it is *POSSIBLE* to skip right by your target time!!!

If some higher priority task came along and gobbled up all the CPU time for
a minute, you might never actually hit your script anytime within that given
minute!

Unlikely, sure. But possible? Absolutely.

So:


Do While True
Wscript.Sleep 5000
objDoc.Location.Reload(True)
If Err <> 0 Then
Wscript.Quit
End If
If Now() >= #09:49# Then
objExplorer.quit
End If
Loop

In VBScript and VB and VB.NET, you can write constant dates and times *AS
DATETIME VALUES* by simply enclosing them in #...#.

Re: "If time = xx.xx Then" not working? by Dr

Dr
Tue Jul 08 04:13:56 CDT 2008

In microsoft.public.scripting.vbscript message <7a02ebcd-4bee-43af-87ec-
0afea8c010a7@d77g2000hsb.googlegroups.com>, Mon, 7 Jul 2008 01:58:20,
skhudy@hotmail.com posted:
>Hi, Not a Vb programmer, trying to get the following working is
>proving difficult.

Further observations :

If for any reason the program is not running at 09:49 (machine in Sleep,
maybe; other processes hogging everything) then it will continue for
another 12 or 24 hours until another 09:49 appears. It's probably
better to use a >= test rather than an = one; that would be more
important if you decided to use seconds.

There is (after moving the Time call) more work being done in the loop
than is necessary. Although it would make no practical difference in
this case, I'd calculate the stop time, or date+time, as a Double in
CDate form *using DateSerial, probably, and/or TimeSerial) before
entering the loop, making the exit condition just Time > stop or
Now>stop .

Consider what might happen if the program were running across midnight.

Considering Sleep again : it might be better to run until the program
has seen, while active, a sufficient number of different minutes.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)