Jump to content

how to end a func


 Share

Recommended Posts

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
Link to comment
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.
Link to comment
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.

Link to comment
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?

Link to comment
Share on other sites

  • Moderators

MirnesC2,

Look at GUICtrlSetData in the Help file.

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

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

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