Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - "If time = xx.xx Then" not working?

Reply
 
Old 07-07-2008   #1 (permalink)
skhudy


 
 

"If time = xx.xx Then" not working?

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

My System SpecsSystem Spec
Old 07-07-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

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


<skhudy@xxxxxx> wrote in message
news:7a02ebcd-4bee-43af-87ec-0afea8c010a7@xxxxxx
Quote:

> 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
--


My System SpecsSystem Spec
Old 07-07-2008   #3 (permalink)
skhudy


 
 

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

On 7 Jul, 13:44, "Richard Mueller [MVP]" <rlmueller-
nos...@xxxxxx> wrote:
Quote:

> <skh...@xxxxxx> wrote in message
>
> news:7a02ebcd-4bee-43af-87ec-0afea8c010a7@xxxxxx
>
>
>
>
>
Quote:

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

> > 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.
>
Quote:

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

> > Thanks
>
Quote:

> > DIM mytime
> > mytime = FormatDateTime(Time(), vbShortTime)
>
Quote:

> > On Error Resume Next
>
Quote:

> > Set objExplorer = CreateObject("InternetExplorer.Application")
>
Quote:

> > objExplorer.Navigate "www.bbc.co.uk"
>
Quote:

> > Wscript.Sleep 5000
>
Quote:

> > Set objDoc = objExplorer.Document
>
Quote:

> > 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
My System SpecsSystem Spec
Old 07-07-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

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


<skhudy@xxxxxx> wrote in message
news:de2d48e5-941b-4c89-bcc2-7e60d9906a71@xxxxxx
On 7 Jul, 13:44, "Richard Mueller [MVP]" <rlmueller-
nos...@xxxxxx> wrote:
Quote:

> <skh...@xxxxxx> wrote in message
>
> news:7a02ebcd-4bee-43af-87ec-0afea8c010a7@xxxxxx
>
>
>
>
>
Quote:

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

> > 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.
>
Quote:

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

> > Thanks
>
Quote:

> > DIM mytime
> > mytime = FormatDateTime(Time(), vbShortTime)
>
Quote:

> > On Error Resume Next
>
Quote:

> > Set objExplorer = CreateObject("InternetExplorer.Application")
>
Quote:

> > objExplorer.Navigate "www.bbc.co.uk"
>
Quote:

> > Wscript.Sleep 5000
>
Quote:

> > Set objDoc = objExplorer.Document
>
Quote:

> > 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


My System SpecsSystem Spec
Old 07-07-2008   #5 (permalink)
Old Pedant


 
 

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

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 #...#.
My System SpecsSystem Spec
Old 07-08-2008   #6 (permalink)
Dr J R Stockton


 
 

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

In microsoft.public.scripting.vbscript message <7a02ebcd-4bee-43af-87ec-
0afea8c010a7@xxxxxx>, Mon, 7 Jul 2008 01:58:20,
skhudy@xxxxxx posted:
Quote:

>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)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
"iTunes not working" message pops up every time i try to open itun Vista installation & setup
Vista "Sleep" and "Hibernate" arent working. Vista performance & maintenance
How to insert the "modified time" attribute in "date taken" attribute in batch mode-in vista or theough a software? Vista file management
How to insert the "modified time" attribute in "date taken" attrib Vista music pictures video
Time Gadget - has no " daylight" time zone Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46