Sign in to follow this  
Followers 0
sulfurious

array question here

4 posts in this topic

#1 ·  Posted (edited)

Hi all.

I need to learn something about arrays. I have looked at a lot of post's, but am still left wondering.

I use _filereadtoarray to fill $Glist[].

I am now using $Glist[] like this

$bHT = 0
Dim $var[$Glist[0]]
For $z = 1 to $Glist[0] - 1
    $var[$z] = GUICtrlCreateButton(StringTrimRight($Glist[$z], 1), 30, $bHT)
Next

This does create the button, but the controlID is always a number. Take a look at this snippet

Dim $hControl[27][4]
For $i = 0 To 26
    $hControl[$i][0] = GUICtrlCreateRadio ($asLabels[$i+1], 27, 100+$i*20, 150, 20)
    $hControl[$i][1] = GUICtrlCreateInput ("1", 200, 100+$i*20, 100, 17)
    $hControl[$i][2] = GUICtrlCreateButton ("Set", 330, 100+$i*20, 40, 17)
    $hControl[$i][3] = GUICtrlCreateButton ("Info", 390, 100+$i*20, 40, 17)
Next

Here the button will be assigned $hControl and something in the array.

How would I construct, I guess it would be a multidimensional array, that passes a $variable with a name as that button controlID? So that I can properly refernce to it in something like a CtrlSetOnEvent?

Everytime I think I have it figured out, I get stuck when I use $whatevervariable = createctrl. Even though that $whatevervariable = $variableIwant prior to createctrl, the controlID is never $variableIwant, but always $whatevervariable. It is like the variable I use, no matter if it SHOULD = something else, is seen only as what is printed on the screen.

I don't wish to contruct the buttons or events for buttons prior, but use the values in the array to dictate how many buttons/events at runtime. I need a $varIwant + $nextnumber = create button so that I can reference to $varIwantnextnumber.

Does this make any sense?

Granted I am very new to this, but there seems to be a lot of confusion with arrays and lot's of snippets and tips, but no really good definitive guidline. At least none I have found wit AutoIT.

BTW, AutoIT is awesome. Thnx to you devolopers

:whistle:

sul

BTW2, I posted very similar in GUI forum, but found more array stuff here so rephrased it.

Edited by sulfurious

Share this post


Link to post
Share on other sites



So I solved half of the issue. Turns out the Assign function does the trick.

For $x = 1 to $array[0] - 1
    $bh = $bh + 30
    Assign("button" & $x, GUICtrlCreateButton($array[$x], 30, $bh)) 
    GUICtrlSetOnEvent(-1, "_func1")
Next

However, am I right in that the "_func1" in the setonevent cannot have any ($,$) variables assigned? Here is the verification that Assign gives the correct CtrlID to $button[$]

Func _func1()
    If @GUI_CtrlId = $button1 Then
        MsgBox(0, "", "it is button1")
    EndIf
EndFunc

If I cannot dyamically assign _func1 with ($,$) from that SetOnEvent, then I must do it in the _func1(). I have tried a for/next to fill in $button($) with the counter, but the for/next did not operate for some reason. I also tried "$button1", but that was incorrect. I could just hardcode the routine, but really wish to learn to do it dynamically.

Any ideas?

sul

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well, solved but not in the fashion I really want. Here is what works.

#include <GUIConstants.au3>
#include <file.au3>
Opt("GUIOnEventMode", 1)
Dim $array,  $bh = 0
_FileReadToArray("c:\Glist.txt", $array)
$win = GUICreate("My GUI", 500, 500)                        
GUISetOnEvent($GUI_EVENT_CLOSE, "_btDLX")                    
GUICtrlCreateLabel("Click to download", 30, 10)                
For $x = 1 to $array[0] - 1
    $bh = $bh + 30    
    Assign("button" & $x, GUICtrlCreateButton(StringTrimRight($array[$x], 1), 30, $bh)) 
;Assign($aa, "_func1" & $x)
    GUICtrlSetOnEvent(-1, "_func1")
Next
GUISetState(@SW_SHOW)
Sleep(2000)
While 1
    Sleep(1000); Idle around
WEnd
Func _func1()
    Select
    Case @GUI_CtrlId = $button1
        MsgBox(0, "", "array component is  " & $array[1])
    ;call function 
    Case @GUI_CtrlId = $button2
        MsgBox(0, "", "array component is  " & $array[2])
    EndSelect
EndFunc
Func _btDLX()
    Exit
EndFunc;==>$download window close with X

I still wish I could figure out how to either assign in the for/next loop, or assign within the function a way to not have to hard code those events in. If my textfile changes (which I plan on) then I either have to build in select/case for futures or recode in the future.

For now I will get the rest of the script done and then continue the battle.

sul.

Edited by sulfurious

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