Sign in to follow this  
Followers 0
Azothoras

Tricky Question....

8 posts in this topic

#1 ·  Posted (edited)

I am sorry for my bad english/phrasing but I am swedish and I am tired hehe.

I am making a program for work that will make the schedule for alot of people. Anyways my problem is in the GUI (as always I suck at GUI's).

The bottom of my problem is that I need to create x number of buttons / labels / whatever. They also needs to be resised to fit the window (This is not a problem)

After all the buttons are created I need to access them in a loop (change the text of them.)

If this is not possible my script will be like 10000000000000000 lines :idea:

Example of how I want to change them.

For $x=1 to $nrbuttons
      GUICtrlSetData($button$x, "New info")
Next

Don't really have to be buttons can be labels or whatever. All I want is for this to be possible hehe.

I really need this because they (the crappy guys at the office) needs to be able to add or remove labels/buttons themselves. Also there will be different ammounts of buttons/labels from day to day. The info on the buttons/labels will also change from day to day.

I hope this is readable and understandable. Please help me out guys.

//Azothoras

Edited by Azothoras

Share this post


Link to post
Share on other sites



This is a very common question and has been answered many times: Arrays.

Keep the control IDs and/or handles in an array. You can easily loop through an array to perform actions on the controls.

:idea:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi, 

could be done this way...

$numberofbuttons = 24   ;number from 1 to 30
Dim $buttoncontrolID[$numberofbuttons + 1]

GUICreate("test")
For $i = 1 To $numberofbuttons ;we make an array of buttons
    $buttoncontrolID[$i] = GUICtrlCreateButton("  Button  " & $i, 10 + ((($i > 10) + ($i > 20)) * 100), 30 + ($i - (($i > (($i > 20) + 1) * 10) * (($i > 20) + 1) * 10)) * 30,85,30)
Next
$somethingbutton=guictrlcreatebutton("do something ",310,30,80,30 )

;here you could give the buttons an other text or color
guictrlsetdata($buttoncontrolID[1] ,"Push!")
GUICtrlSetColor($buttoncontrolID[1],0xFF00FF)
guictrlsetdata($buttoncontrolID[13],"Push ME!")
GUICtrlSetColor($buttoncontrolID[13],0x000FFF)
guictrlsetdata($buttoncontrolID[17],"Push ME TOO!")
GUICtrlSetColor($buttoncontrolID[17],0xFF0000)

GUISetState()



While 1
    $msg = GUIGetMsg()
    ;ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $msg = ' & $msg & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    Switch $msg
        Case -3  ;exit is pressed
            Exit
        case $somethingbutton
            Msgbox (0,"","Button ""do something"" is pressed")

        Case $buttoncontrolID[1] To $buttoncontrolID[$numberofbuttons]   ;one of the "array"-Buttons is pressed
           call ("_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg)))  ;names oft the functions are _arraybutton_1() _arraybutton_2().....
            If @error = 0xDEAD And @extended = 0xBEEF Then MsgBox(4096, "ERROR", "Function "&"_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg))&" does not exist!")
    EndSwitch
WEnd



;*******************functions********************************
func _arraybutton_1()

    msgbox(0,"_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg)),"arraybutton pressed: "&GUICtrlRead($msg))
endfunc
;
; here are the funcs of the buttons
;
;
func _arraybutton_13()
    msgbox(0,"_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg)),"arraybutton pressed: "&GUICtrlRead($msg))
endfunc

func _arraybutton_17()
    msgbox(0,"_arraybutton_"&($numberofbuttons-($buttoncontrolID[$numberofbuttons]-$msg)),"arraybutton pressed: "&GUICtrlRead($msg))
endfunc

/EDIT/ @gui_ctrlid and @gui_ctrlhandle are also worth to take a look at

Edited by AndyG

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

lol now I remember why I don't come to this forum much... Such assholes

Ty PsaltyDS and AndyG

Edited by Azothoras

Share this post


Link to post
Share on other sites

lol now I remember why I don't come to this forum much... Such assholes

When that is how you feel then better stay away....

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

When that is how you feel then better stay away....

But then he would be so sadly missed by all of us.

AdmiralAlkex wan't really wrong here IMHO, the OP has been a member for 5 years and obviously still hasn't spent much time in the help file. It was written in less time than that.


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!"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

lol now I remember why I don't come to this forum much... Such assholes

The only one being an asshole here is you. I just stated the truth (that you suck at arrays) and linked you to the tutorial. If you have such problems accepting reality you should just go back to that cave you came from and stay there. Edited by AdmiralAlkex

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