aghering

[Question] Use GuiControlSetData in loop

9 posts in this topic

Hello,

I have question on how to use GUICtrlSetData in a Do.. Until.. Loop.

Local $a= 0, $b= 1, $c= 2
Do
    GUICtrlSetData('lab_SItemAmount'& $b, $SCA_LeftRow[$a])
    GUICtrlSetData('$lab_SItemAmount'& $c, $SCA_RightRow[$a])
    $a= $a + 1
    $b= $b + 2
    $c= $c + 2
Until $a= 5

In the above code, i got the value's i need in array's and i am trying to set the value to labels on my GUI.

My labels are named "$lab_SItemAmount1.2.3...10", with even numbers on the right side and uneven numbers on the left side.

The problem i am facing is that cannot seem to call my labels variable in the way i'm using above,  i have tried many different ways with no luck.

Any suggestions?

Share this post


Link to post
Share on other sites



aghering,

Either use Eval to get each label ControlID when required or, much better, store the label ControlIDs in an array and loop through them. :)

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

Also, check out GuiCtrlSetData in the Help file.  The first parm is a control ID...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thank you for taking the time to answer my question.

I was looking for the "Eval" command in the autoit help file but with no references to Eval on the "GuiCtrlSetData" page and looking for Control ID gives to many hits,  is kinda difficult to find your result.

Its good to know about the existence of "Eval" but i think i am going for your suggestion on storing the Control ID in a Array.

I tested at work with a quick and dirty script and works nice.

Question is Answered! 

I got a question on the side: my programming skill are getting better lately and focusing much more in making a efficient/clean code; is there a away to make this loop more efficient and less static?

Share this post


Link to post
Share on other sites

aghering,

 

I was looking for the "Eval" command in the autoit help file

Obviously not very hard - Eval. :D

But using arrays is by far the best way. :)

As to streamlining, why not use an algorithm to determine the other 2 variables? This seems functionally identical:

Local $a= 0, $b= 1, $c= 2
Do

    ConsoleWrite($a & " - " & $b & " - " & $c & @CRLF)
    $a= $a + 1
    $b= $b + 2
    $c= $c + 2

Until $a= 5

ConsoleWrite(@CRLF)

For $i = 0 To 4

    ; Derive the other variables from the first
    ConsoleWrite($i & " - " & (2 * $i) + 1 & " - " & (2 * $i) + 2 & @CRLF)

Next
Any use? :huh:

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
is there a away to make this loop more efficient and less static?

 

Can you define this a little more clearly?


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

aghering,

Here is a couple of way that static labels might be created and populated...

#include <GUIConstantsEx.au3>

#AutoIt3Wrapper_Add_Constants=n

example1()
example2()

func example1()

    local $aCTLD[10]

    local $gui010 = guicreate('GuiCtrlSetData Example', 370,300)

    $aCTLD[0] = guictrlcreatelabel('',50,10,100,20)
    $aCTLD[1] = guictrlcreatelabel('',50,30,100,20)
    $aCTLD[2] = guictrlcreatelabel('',50,50,100,20)
    $aCTLD[3] = guictrlcreatelabel('',50,70,100,20)
    $aCTLD[4] = guictrlcreatelabel('',50,90,100,20)
    $aCTLD[5] = guictrlcreatelabel('',220,10,100,20)
    $aCTLD[6] = guictrlcreatelabel('',220,30,100,20)
    $aCTLD[7] = guictrlcreatelabel('',220,50,100,20)
    $aCTLD[8] = guictrlcreatelabel('',220,70,100,20)
    $aCTLD[9] = guictrlcreatelabel('',220,90,100,20)

    for $1 = 0 to ubound($aCTLD) - 1
        guictrlsetdata($aCTLD[$1], 'Static Label # ' & stringformat('%03i', $1 + 1))
    next

    guisetstate()

    while 1
        switch guigetmsg()
            case $gui_event_close
                guidelete($gui010)
                return
        EndSwitch
    WEnd

endfunc

func example2()

    local $aCTLD[10]

    local $gui010 = guicreate('GuiCtrlSetData Example', 400,300)

    local $idx = 0
    for $1 = 1 to 2
        for $2 = 1 to 5
            $aCTLD[$idx] = guictrlcreatelabel('',$1 * 100, $2 * 30 + 10, 50, 20)
        $idx += 1
        next
    next

    for $1 = 0 to ubound($aCTLD) - 1
        guictrlsetdata($aCTLD[$1], stringformat('%03i', $1 + 1))
    next

    guisetstate()

    while 1
        switch guigetmsg()
            case $gui_event_close
                Exit
        EndSwitch
    WEnd

endfunc

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The examples you guys gave me looks good and going to use them as a reference,

I got the Array part worked out (initial question) and i will have a look at the method how  bohica worked out the guictrlcreatelabel.  

Thanks again for your input!

Edited by aghering

Share this post


Link to post
Share on other sites

Good, glad it helped...any questions just ask...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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