Jump to content
Sign in to follow this  
wonnylee

how to terminate function?

Recommended Posts

wonnylee

My script is organized like this.

Main function

{

GUI CREATED.

button 1 -> run function A

}

A function

{

........

......

..........

}

when i click button 1 in main function, A function is called and started with pop-up window.(including buttton 2 in pop-up window)

And What i 'm wanting to do is like this..

if i click button 2 in pop-up window, i want to stop the A function. but A function script is quite long, so i cannot do it with while function.

How can i stop the A function, while running A function?? and return to main function,,,,

cf) A function is called by main function.

i dunno where and how to put RETURN.. in A function..

plz help...

thanks

Share this post


Link to post
Share on other sites
cageman

if you want to functio to end just type return 0 for example or any other result. if you want to return $result for example:

return $result

that would exit the function immediatly

Share this post


Link to post
Share on other sites
Melba23

wonnylee,

You will have to poll GUIGetMsg() from within Function A to see if Button 2 has been pressed. If you have an existing While...WEnd (or similar) loop then it is easy to insert. If not, then you might want to think along the following lines:

#include <GUIConstantsEx.au3>

AdlibEnable("Function_C")
Global $fFlag = False

$hGUI = GUICreate("Test", 500, 500)

$hButton_1 = GUICtrlCreateButton("Func A", 10, 10, 80, 30)
$hButton_2 = GUICtrlCreateButton("Func B", 10, 50, 80, 30)

$hLabel_1 = GUICtrlCreateLabel("",   100, 10, 150, 20)
$hLabel_2 = GUICtrlCreateLabel($fFlag, 100, 50, 150, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            AdlibDisable()
            Exit
        Case $hButton_1
            Function_A()
    EndSwitch

WEnd

Func Function_A()
    GUICtrlSetData($hLabel_1, "Function A running")
    Local $begin = TimerInit()
    While TimerDiff($begin) < 20000
        Sleep(200)
        If $fFlag Then
            Function_B()
        EndIf
    WEnd
    GUICtrlSetData($hLabel_1, "Function A ended")
EndFunc

Func Function_B()
    MsgBox(0, "", "Button 2 pressed!")
    Global $fFlag = False
    GUICtrlSetData($hLabel_2, $fFlag)
EndFunc

Func Function_C()
    Local $begin = TimerInit()
    While TimerDiff($begin) < 50
        If GUIGetMsg() = $hButton_2 Then
            $fFlag = True
            GUICtrlSetData($hLabel_2, $fFlag)
        EndIf
    WEnd
EndFunc

This not perfect, but does work.

M23

Edit: Sorry, I should have made clear that you do NOT need a While...WEnd loop within Function A. If you do not have a loop then you just need to test the $fFlag from time to time during Function A using:

If GUIGetMsg() = $hButton_2 Then
    $fFlag = True
    GUICtrlSetData($hLabel_2, $fFlag)
    ; Here you need to decide whether to continue with Function A (do nothing) or go back to the main loop (Return)
EndIf
Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Melba23

Inverted,

That is exactly why I used Adlib in the example above! ;-)

I agree it is very useful - and even more so in the new Beta.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Inverted

Your solution uses the standard Adlib and requires a while loop. The OP noted that he'd rather avoid that.

It seems _Adlib.au3 could be a better/easier/more robust solution. It even has pause/resume funcitonality ...

Share this post


Link to post
Share on other sites
Melba23

Inverted,

Apologies, misread your post.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
wonnylee

thanks for your help.

I used AdlibEnable function with 3sec option, ..

Main Func()
  GUICREATE,
   buttonCreate A -> Run Func A
EndFunc

Func A
  EnableAdlib("Stop", 3000)
  popup window(handle_popup) with button
  create button KKK -> If button is clicked, Function A should be terminated and return to main function GUI  
  ........
.........
................
.............

EndFunc

Func Stop()
    $msg_3 = GUIGetmsg()
     Local $begin = TimerInit()
    While TimerDiff($begin) < 50
        If GUIGetMsg() = $button_KKK Then
            GUISetState(@SW_HIDE, $handle_popup)
             Return 0
        EndIf
    WEnd
EndFunc

but with this , even if i click button KKK several times(for longer than 3 sec), func A cannot be stopped.

'RETURN' doesn't work for function A, i think it only works in Stop function.

I want terminate func A, while function A is running ,,, when i click button KKK..

plz help..

Share this post


Link to post
Share on other sites
Melba23

wonnylee,

As you have discovered it is not easy to break into a running function. Please post your "Function_A" so the internal structure can be seen - it might help.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.