Jump to content

Trouble with @gui_ctrlid


Recommended Posts

Func Loadsaved()
    Local $savedname
    If @error Then
        Switch @GUI_CtrlId
            Case $quickloadsGUI[0]
                $savedname = "save1"
            Case $quickloadsGUI[1]
                $savedname = "save2"
            Case $loadlistGUI
                $savedname = GUICtrlRead($savedattackzonelistGUI)
                Select
                    Case _GUICtrlListBox_GetCurSel($savedattackzonelistGUI) = -1
                        MsgBox(0x10, "Error", "No save selected")
                        Return
                EndSelect
            Case Else
                $savedname = "defaults"
        EndSwitch
    Else
        $savedname = "defaults"
    EndIf
endfunc
Hello programmers,

(What a nice way to greet people here =P) I am having trouble with my function. The function can be called by guisetonevent, from the buttons in my GUI, but I also want to call the function one time at the beginning of the program without going through a button or guisetonevent. However, when I do this, the program halts with the error that the macro is unknown. What is the solution? I've tried a few things to get around it, like creating an if and then statement... I could easily get around it if I make a variable to determine if the function was called not by a button--that would be ugly programming though. Any ideas? Am I missing something?

Link to comment
Share on other sites

Hmm, since @GUI_CtrlId is only valid once a control has been clicked, maybe you should controlclick() something at the start of your script.

(Yes, you said you don't want to go through onevent, but you must go through it to enable @GUI_Ctrlid)

Otherwise you'll have to do some roundabout way like you said (WIth a variable or separate functions)

Edited by hawky358
Link to comment
Share on other sites

  • Moderators

crislivinitup,

As you will only using one of the 4 Cases when you call the function at the beginning of your script, and they are all short, why not just code it directly and avoid the function altogether? At most it would add a few lines to the script. :idea:

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

crislivinitup,

As you will only using one of the 4 Cases when you call the function at the beginning of your script, and they are all short, why not just code it directly and avoid the function altogether? At most it would add a few lines to the script. :idea:

M23

Melba, I appreciate your reply, thank you for that; second, I don't know what you're talking about :). I'm not familiar with these, '4 cases', out of curiousity--and for the sake of becoming a better programmer--would you please fill me in?

I would like to suggest to the smart AutoIt Developer team to include a failsafe with the use of @gui_ctrlid. I believe instead of crashing it should set @error. A small thing that would make AutoIt just a little better.

Lastly, I want to explain the solutions I see to this problem in hopes of someone correcting and/or adding to this. I enjoy to be corrected or taught--I always want to be a better programmer. I only see a few basic solutions to this.

1: I have to send a null(useless)controlclick to the GUI to make @gui_ctrlid "stable" to use as a switch.

2: I could create a global variable that is used one time as a switch to tell my program that it is safe to check @gui_ctrlid...

that is to say, I would create an if...then statement including this variable in such a way that it will not check @gui_ctrlid until this variable is True.

3: I could use a seperate function that I will title loadsavedGUI() which will be used to check the @gui_ctrlid and send it as a parameter to loadsaved(). *I had tried changing loadsaved() to a function that accepts parameters, because it was one that worked with ctrls it didn't work out well (I feel it's not necessary to explain details)

4: I could simply copy the contents of the funtion and put in the trainer without the @gui_ctrlid and code it without the use of a switch because I know exactly the path I want it to take already.

1, looks a little ugly to me but is probably the quickest solution to my problem.

2, I don't want to create a conditional statement that will keep checking (and adding cycles to my program =P) when it's only going to be used 1 time... it just feels not like good programming practice.

3, Ugly solution as well

4, This is what I had originally actually, but I seek to optimize my code and save space. When I realized I could use @gui_ctrlid (honestly I had no idea until somebody told me about the macro in a post I made--I know I should have carefully read the helpfile... shame on me).

Hawky, thanks for the advice on the controlclick, that's what I will probably do to tackle my problem.

Link to comment
Share on other sites

I did tried the controlclick to a label or something null and it did not work because it did not set @gui_ctrlid... it worked only after I chose a button. For your consideration.

Yes, that's what I meant, it has to be something that activates the Guictrlsetonevent(). I thought maybe you had a "default" button or something like that. (You could make a hidden default button.)

Link to comment
Share on other sites

Melba, I appreciate your reply, thank you for that; second, I don't know what you're talking about :idea:. I'm not familiar with these, '4 cases', out of curiousity--and for the sake of becoming a better programmer--would you please fill me in?

What Melba meant by '"4 cases" is this

Switch @GUI_CtrlId
            Case $quickloadsGUI[0]
                $savedname = "save1"
            Case $quickloadsGUI[1]
                $savedname = "save2"
            Case $loadlistGUI
                $savedname = GUICtrlRead($savedattackzonelistGUI)
                Select
                    Case _GUICtrlListBox_GetCurSel($savedattackzonelistGUI) = -1
                        MsgBox(0x10, "Error", "No save selected")
                        Return
                EndSelect
            Case Else
                $savedname = "defaults"

So instead of calling the loadsaved() function at the start of the script you just add these lines, which will result in $savedname = "defaults", since you didn't click anything?

So why not just define $savedname = "defaults" ?

Link to comment
Share on other sites

What Melba meant by '"4 cases" is this

Switch @GUI_CtrlId
            Case $quickloadsGUI[0]
                $savedname = "save1"
            Case $quickloadsGUI[1]
                $savedname = "save2"
            Case $loadlistGUI
                $savedname = GUICtrlRead($savedattackzonelistGUI)
                Select
                    Case _GUICtrlListBox_GetCurSel($savedattackzonelistGUI) = -1
                        MsgBox(0x10, "Error", "No save selected")
                        Return
                EndSelect
            Case Else
                $savedname = "defaults"

So instead of calling the loadsaved() function at the start of the script you just add these lines, which will result in $savedname = "defaults", since you didn't click anything?

So why not just define $savedname = "defaults" ?

Oh I see... please excuse me hahaha. I didn't realize he was referring to my switch...case statement :idea:. The reason I didn't do that is because the function itself is actually very large. I only copied the problem part of it. The buttons will also use this function and by doing this, updating is much easier. I started getting problems because I had a few different places in code that were made to do the same thing and I wasn't being consistent--I forgot small bits here and there. Thanks for the reply.

Link to comment
Share on other sites

What exactly are you attempting to return at load time? Put that portion in a separate function that can be called at startup AND from a case statement in the existing function. As it stands right now, your code may show the section with the problem but it doesn't really show where the problem could be since there is nothing being returned and the only variable being acted upon is $savedname which is declared as local anyway so it has no effect on the rest of your script.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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