Jump to content

how to terminate function?


Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Inverted,

Apologies, misread your post.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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