![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | "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 Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | 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 - |
My System Specs![]() |
| | #4 (permalink) |
| | 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 - ==================== 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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. 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 Specs![]() |
![]() |
| 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 | |||