Sign in to follow this  
Followers 0
MirnesC2

how to end a func

8 posts in this topic

#1 ·  Posted (edited)

Hi, well I have a code its set up something like this...

; some gui stuff here
; buttons, labels, bla bla

While 1
    $msg = GUIGetMsg()
    If $msg = $edit Then
        Call("EditPanel")
    EndIf
    If $msg = $save Then
        MsgBox(48, "Saved", "Save Completed", 10)
Until $msg = $msg = $GUI_EVENT_CLOSE

Func EditPanel()
    ;some gui stuff here
    ;other code bla bla
    If $msg = $close OR $msg = $GUI_EVENT_CLOSE Then
        GUIDelete("EditPanel")
    EndIf
EndFunc

It's basically a main GUI panel with a bunch of options such as... save and edit. When you press edit it opens a new window, all the new window gui and code is inside the function EditPanel(). Now I figured out how to delete the gui of the EditPanel() but it's still inside the function so the buttons from the main GUI menu still don't work.

My questions is what do I add after GUIDelete("EditPanel") to exit the function EditPanel() and go back to the main menu/GUI. Or is there an easier way to do this?

Edited by MirnesC2

Share this post


Link to post
Share on other sites



Hi, well I have a code its set up something like this...

; some gui stuff here
; buttons, labels, bla bla

While 1
    $msg = GUIGetMsg()
    If $msg = $edit Then
        Call("EditPanel")
    EndIf
    If $msg = $save Then
        MsgBox(48, "Saved", "Save Completed", 10)
Until $msg = $msg = $GUI_EVENT_CLOSE

Func EditPanel()
    ;some gui stuff here
    ;other code bla bla
    If $msg = $close OR $msg = $GUI_EVENT_CLOSE Then
        GUIDelete("EditPanel")
    EndIf
EndFunc

It's basically a main GUI panel with a bunch of options such as... save and edit. When you press edit it opens a new window, all the new window gui and code is inside the function EditPanel(). Now I figured out how to delete the gui of the EditPanel() but it's still inside the function so the buttons from the main GUI menu still don't work.

My questions is what do I add after GUIDelete("EditPanel") to exit the function EditPanel() and go back to the main menu/GUI. Or is there an easier way to do this?

I assume your real code has the If/GuiDelete/endif inside a while loop, otherwise the function as you've shown it will just end and return to the main script.

Best not have the same variable name ($msg) in the function to avoid problems. Better to declare a local variable in the function with a different name.

Anyway, to return from a function just use Return.

If $timetoleave Then
 cleanup()
 Return
EndIf

BTW, there is no advantage in using Call instead of the function name.

EditPanel(); better than Call("EditPanel")

Call is useful when you need a variable for the function name. I can't think of any other reason to use it at the moment.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I assume your real code has the If/GuiDelete/endif inside a while loop, otherwise the function as you've shown it will just end and return to the main script.

Best not have the same variable name ($msg) in the function to avoid problems. Better to declare a local variable in the function with a different name.

Anyway, to return from a function just use Return.

If $timetoleave Then
 cleanup()
 Return
EndIf

BTW, there is no advantage in using Call instead of the function name.

EditPanel(); better than Call("EditPanel")

Call is useful when you need a variable for the function name. I can't think of any other reason to use it at the moment.

Oh!, Return... so simple, lol. I accidentally hit the - reputation button, but I went back to some of your others posts and hit the + to re-balance it. Sorry, they really need a confirmation window or undo button on that thing o.o

Thank you!, and thanks for the call function tip.

Share this post


Link to post
Share on other sites

I got it working, thanks. One more problem though.

Lets say I have the main gui/panel/frame. It has a label that says "hello". Now I got to 2nd gui/panel/frame and edit it to say "whats up" instead of hello. When I save and exit out the 2nd gui/panel/frame the label "hello" on main frame still says "hello" instead of "whats up". How can I fix that? How can make it update or reset the gui?

Share this post


Link to post
Share on other sites

MirnesC2,

Look at GUICtrlSetData in the Help file.

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

MirnesC2,

Look at GUICtrlSetDatain the Help file.

M23

It shows an example with combo box, I don't really understand it. Is it possible to make an example with label instead?

Share this post


Link to post
Share on other sites

MirnesC2,

Click either the button or the label itself:

#include <GUIConstantsEx.au3>

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

$hLabel = GUICtrlCreateLabel("First line of text", 10, 10, 300, 30)

$hButton = GUICtrlCreateButton("Change", 10, 50, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton, $hLabel
            If GUICtrlRead($hLabel) = "First line of text" Then
                GUICtrlSetData($hLabel, "Second line of text")
            Else
                GUICtrlSetData($hLabel, "First line of text")
            EndIf

    EndSwitch

WEnd

To really understand functions you need to play with the Help file examples and see what results you get. It is the best way to learn. :)

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

Ah, great! Thank you so much, I got it to work now.

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  
Followers 0