Jump to content

[Doubt] While + Call Function


Recommended Posts

HotkeySet("F2", "Example")

While 1

    $a = 1
    $b = 2
    $c = 3
    $d = 4
    $d = 5
    $e = 6   
    
Wend

Func Example()

    $x = 0
    
EndFunc

Suppose i press F2 while the loop are in line:

$c = 3

My doubt is, when the func ends the script returns to the begin of the loop ($a =1) or the line it was when i  pressed F2 ($c = 3)?

Link to comment
Share on other sites

1) the HotKeySet() help page is quite clear at this point.

2) while you're at it - what do you think should happen?

3) and what do you think should happen in a more complex scenario - like calling the hotkey inside a function? or inside a nested loop?

4) and why won't you check it yourself? run this and try. i won't provide any spoilers :-)

HotKeySet("{F2}", "Example")
Global $a
Global $bReport = False
Do
    $a = 1
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 2
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 3
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 4
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 5
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 6
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
Until $bReport

Func Example()
    ConsoleWrite('hello, you pressed F2.' & @CRLF)
    $bReport = True
EndFunc   ;==>Example

 

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

yes, it is possible, but before you do, you might want to review your logic.

if you want to do that anyways, then in the loop pick some key checkpoints to allow a safe ContinueLoop, and change the condition of the $bReport check to ContinueLoop instead of ConsoleWrite(). also change the loop condition to disregard $bReport, and instead, in the first line of the block of code inside the loop, you must re-initialize $bReport back to False.

also, naturally, rename $bReport to $bContinueLoop or such.

 

 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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