Jump to content
Sign in to follow this  
Diana (Cda)

[RESOLVED] Error: "While" statement has no matching "Wend" statement.

Recommended Posts

Diana (Cda)

In "cleaning up" this script, I must have done something wrong. Have gone through with fine-tooth comb, but don't know how to fix.

This here:

;
; AutoIt 3x
;
#Include<_SYSTRAY, refresh.au3>
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon(@ScriptDir & "\PUAC- 01- start PUAC (+loops).ico")

;===== Start new systray script:  =================================================================
;  Systray button commands here:
Opt("GuiOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
;-------------------------------------------------------------------------
TrayCreateItem("Start PUAC")
TrayItemSetOnEvent(-1, "_StartPUAC")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Quit")
;  Functions for the buttons above follow within the GUI code found near bottom, below.
;==================================================================================================

;-----------------------------------------------------------------------------------
$oSp = ObjCreate("SAPI.SpVoice")
$oSp.Speak("Closing poo ack, and starting up tray script.")  ; voice prompt for this PUAC script.
Sleep(1000)
;-----------------------------------------------------------------------------------
    Beep(1500,50)
    Beep(1000,75)
    Beep(1500,50)
    Beep(1000,75)
    If ProcessExists("Puac.exe") Then ProcessClose ("Puac.exe")
    _RefreshSystemTray()     ; removes lingering icons from systray after PUAC close
;-----------------------------------------------------------------------------------

Sleep(1500)

While 1
SoundPlay(@ScriptDir & "\WAV-PrPrint.wav")
Sleep(2500)

Func _StartPUAC()
    Sleep(500)
    $oSp.Speak("Launching poo ack, if it isn't already running.")  ; voice prompt for this PUAC script.
    Sleep(1000)
    GUISetIcon(@ScriptDir & "\PUAC- 01- start PUAC (+loops).ico")
    SoundPlay(@ScriptDir & "\WAV-Wookie.wav")
    $SamePartition = StringLeft(@ScriptDir, 2)
    If NOT ProcessExists("Puac.exe") Then ShellExecute($SamePartition & "\alarm,TaskScheduler - PUAC v2.0.7\APP- PUAC v2.0.7\Puac.exe")
    Sleep(1500)
    Exit     ; finished
EndFunc   ;==>_Continue
Func _Quit()
    Exit     ; finished
EndFunc   ;==>_QuitExit

Sleep (5000)     ; Sleep for 1,800,000 = 30 minutes / 60,000 units = 1 minute / 30,000=30 seconds / 15,000=15 seconds / 10,000=10 seconds / 5,000=5 seconds

WEnd
the script works but then doesn't stay in residence.

Thanks in advance. Hope that by seeing what fixes this one, will finally learn about what I sometimes miss re While ... WEnd. muttley

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites
Jos

You cannot have a Func-EndFunc inside any loop like While-Wend, just simply not allowed. Move the Func-EndFunc to the bottom and call the Func inside the loop by doing: _StartPUAC()

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Diana (Cda)

You cannot have a Func-EndFunc inside any loop like While-Wend, just simply not allowed. Move the Func-EndFunc to the bottom and call the Func inside the loop by doing: _StartPUAC()

Jos

Thanks, Jos. That's good to know. I was in a real bind because the script did work before I touched it today but found that I actually had an older version before which wasn't easy to recognize as I didn't know this about no Func-EndFunc inside While-WEnd. I screwed up, in other words by providing wrong script. I have to look at it in a positive way - extra practice for me <g>. Anywho, got even more practice by cleaning up this one, the _right_ one, and here it is as it stands now:
;
; AutoIt 3x
;
#Include<_SYSTRAY, refresh.au3>
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
;-------------------------------------------------------------------------
$oSp = ObjCreate("SAPI.SpVoice")
$oSp.Speak("Closing poo ack, and starting up tray script.")  ; voice prompt for this PUAC script.
Sleep(1000)
;-------------------------------------------------------------------------
    If ProcessExists("Puac.exe") Then ProcessClose ("Puac.exe")
    _RefreshSystemTray()     ; refreshes the systray of lingering icons after PUAC close
;----------------------------------------------------------------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------------------------------------------------------
;----- Tray script: ---------------------------------------------------------------------------------------------------------------------------------
#include <GuiConstants.au3>
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon(@ScriptDir & "\PUAC- 02- _CLOSE_ PUAC + and start tray script (+loops).ico")

Beep(1000,100)
Beep(750,200)
Beep(1000,100)
Beep(750,200)
Beep(1000,100)
Beep(750, 25)
Beep(1000,100)
Beep(750,200)

;===== Tray "context" menu items: ========================================
Opt("GuiOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
;-------------------------------------------------------------------------
TrayCreateItem("Start PUAC")
TrayItemSetOnEvent(-1, "_StartPUAC")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Quit")
;=========================================================================

While 1
$fStartPUAC = False ; <=== Bug fix, reset continue flag to prevent constant beeping    (holdover syntax from older script that still seems to work here)
WEnd

Func _StartPUAC()
    Sleep(500)
    $oSp.Speak("Launching poo ack, if it isn't already running.")  ; voice prompt for this PUAC script.
    Sleep(1000)
    GUISetIcon(@ScriptDir & "\PUAC- 01- start PUAC (+loops).ico")
    SoundPlay(@ScriptDir & "\WAV-Wookie.wav")
    $SamePartition = StringLeft(@ScriptDir, 2)
    If NOT ProcessExists("Puac.exe") Then ShellExecute($SamePartition & "\alarm,TaskScheduler - PUAC v2.0.7\APP- PUAC v2.0.7\Puac.exe")
    Sleep(1500)
    Exit     ; finished
EndFunc   ;==>_Continue

Func _Quit()
    Exit
EndFunc   ;==>_Quit

I'm very curious about one thing, what is making it stay in residence in the tray? That $fStartPUAC is a holdover from someone's very kind contribution to the script initially. Yet I don't see what it's calling. When I commented out the While-WEnd with $fStartPUAC, the script does its job but winks out of the systray. So, to better understand this, why does that $fStartPUAC in While-WEnd keep the script in the systray, pls (besides because it's within the While-WEnd)?

Thanks!!! muttley

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites
Jos

The While-Wend loop keeps the Script active till a option on the systray menu is selected. I would add a Sleep(10) in there to minimise the CPU utilisation.

I have no idea what the "$fStartPUAC = False" is doing there and doesn't seem to be used anywhere in the script.

Do you also really want to exit the script when selecting "Start PUAC" ?

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Diana (Cda)

The While-Wend loop keeps the Script active till a option on the systray menu is selected. I would add a Sleep(10) in there to minimise the CPU utilisation.

Oh, okay. Sounds kewl. I changed ...
While 1
$fStartPUAC = False ; <=== Bug fix, reset continue flag to prevent constant beeping    (holdover syntax from older script that still seems to work here)
WEnd
and, you're right, still works.

I upped it from 10 to 1000 in the sleep since 10 didn't seem like very much <g>. Seems to still work. I still have my "tray context menu" available from the script.

I have no idea what the "$fStartPUAC = False" is doing there and doesn't seem to be used anywhere in the script.

You're right. Now I know it really isn't needed any more.

Do you also really want to exit the script when selecting "Start PUAC" ?

Jos

Yes. The whole idea is that when I leave home to do errands on the weekends, for example, but leave the computer on, this script stops my launcher/scheduler but puts an icon in the systray so that I can launch it again once I get home. So PUAC is turned off while this script is running in the tray. Yet when I launch PUAC with it after I get in, no longer need this script so it closes down. I have the script available in my QuickLaunch bar which I have located always just to the left of the systray rather than its default location just to the right of the start button.

p.s., PUAC is another miracle freeware that launches apps, and/or speech reminders, etc. PUAC stands for "Peter's Ultimate Alarm Clock" <g>. Kewl.

Thanks! Learned a lot today, again. muttley

Share this post


Link to post
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
Sign in to follow this  

×