Jump to content

While loop problem.


Recommended Posts

Ok, so I am trying to write to a file, but ONLY during a certain time of day. I do not want the loop to end. The error I get is: "Error: Wend statement with no matching while statment."

What I have so far is this: (I have also attached the autoit script file if that is easier to look at). 

 
$counter = 1
While $counter = 1 ; loops 
 
   If("063000" > @HOUR & @MIN & @SEC < "071500" ) Then  ; Determines if the time is between 6:30am and 7:15am  
   
 FileDelete("test.txt") ; Deletes test.txt file (assuming it is already there)
   
 $file = FileOpen("test.txt", 1) ; Creates new text.txt file
 
 FileWrite($file, "Bla bla bla bla" & " " & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC & "-" & @YEAR & @CRLF)  ; (CRLF = Linebreak)   Writes line and records date and time
 
 FileClose($file) ; Closes file
   
   Else   ; If time is not between 6:30am and 7:15am, sleep for another 15 minutes
   Sleep(900000)
  
WEnd ; ends loop (loop should never end)
 

StartupWriteFile.au3

Link to comment
Share on other sites

You have no EndIf.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

AND (pun intended) your If statement is constructed wrong, besides not having an EndIf. Compare your code to this UDF.

;===============================================================================
; Function Name: _Time_InRange()
; Description: Determine if the current time is within a given Range
; Syntax: _Time_InRange("Low time", "High time")
; Parameter(s): $sTime - Low end of the range (Start time)
; $eTime - High end of the range (End time)
; Requirement(s):
; Return Value(s): 1 if current time is within the range otherwise 0
; Author(s): George (GEOSoft) Gedye
; Modification(s): Replaced _NowTime(4) With Formatted @Hour & @Min
; Note(s): This only uses Hours and Minutes
; Example(s): MsgBox(0, "Time is good", _Time_InRange("08:00", "23:59"))
;===============================================================================

Func _Time_InRange($sTime, $eTime)
Local $vRange = 0, $cTime
$cTime = Number(@Hour & @Min)
If $cTime >= Number(StringFormat("%04d",StringRegExpReplace($sTime, "\D", ""))) AND _
$cTime <= Number(StringFormat("%04d",StringRegExpReplace($eTime, "\D", ""))) Then $vRange = 1
Return $vRange
EndFunc ;<==> _Time_InRange()
Take note that the If statement in that function doesn't have (or need) an EndIf because it is all one line (refer to the underscore in the Help file) Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...