Mellowz Posted April 28, 2007 Posted April 28, 2007 I have a program that loads the skill names into a drop-down box using GUICtrlSetData. This is the longer version which works: expandcollapse popup$LoopID = 0 While StringLen($Data_SkillName[$LoopID]) <> 0 GUICtrlSetData($SkillName_1, $Data_SkillName[$LoopID]) $LoopID = $LoopID + 1 WEnd $LoopID = 0 While StringLen($Data_SkillName[$LoopID]) <> 0 GUICtrlSetData($SkillName_2, $Data_SkillName[$LoopID]) $LoopID = $LoopID + 1 WEnd $LoopID = 0 While StringLen($Data_SkillName[$LoopID]) <> 0 GUICtrlSetData($SkillName_3, $Data_SkillName[$LoopID]) $LoopID = $LoopID + 1 WEnd $LoopID = 0 While StringLen($Data_SkillName[$LoopID]) <> 0 GUICtrlSetData($SkillName_4, $Data_SkillName[$LoopID]) $LoopID = $LoopID + 1 WEnd $LoopID = 0 While StringLen($Data_SkillName[$LoopID]) <> 0 GUICtrlSetData($SkillName_5, $Data_SkillName[$LoopID]) $LoopID = $LoopID + 1 WEnd $LoopID = 0 While StringLen($Data_SkillName[$LoopID]) <> 0 GUICtrlSetData($SkillName_6, $Data_SkillName[$LoopID]) $LoopID = $LoopID + 1 WEnd $LoopID = 0 While StringLen($Data_SkillName[$LoopID]) <> 0 GUICtrlSetData($SkillName_7, $Data_SkillName[$LoopID]) $LoopID = $LoopID + 1 WEnd $LoopID = 0 While StringLen($Data_SkillName[$LoopID]) <> 0 GUICtrlSetData($SkillName_8, $Data_SkillName[$LoopID]) $LoopID = $LoopID + 1 WEnd As you can see, this array gets loaded into 8 different drop-down box variables. Now, I'm trying to make it a bit shorter: For $LoopID = 1 To 9 Step + 1 $LineID = 0 While $Data_SkillName[$LineID] <> "" MsgBox(0, "DEBUG", $SkillName_ & $LoopID) GUICtrlSetData($SkillName_ & $LoopID, $Data_SkillName[$LineID]) $LoopID = $LoopID + 1 WEnd Next The problem occurs in this line: GUICtrlSetData($SkillName_ & $LoopID, $Data_SkillName[$LineID]) It complains about the use of the & symbol. However, this command works which is odd... MsgBox(0, "TEST", $SkillName & $LoopID) Any help would be appreciated.
Valuater Posted April 28, 2007 Posted April 28, 2007 try this... GUICtrlSetData(Eval($SkillName_ & $LoopID), $Data_SkillName[$LineID]) 8)
Mellowz Posted May 5, 2007 Author Posted May 5, 2007 Didn't work. That returns what's inside a variable. I want to actually combine a variable with a number. For example. If the variable NAME is $Skill_ I want to be able to add 1 to the end of it so it appears like $Skill_1
PsaltyDS Posted May 5, 2007 Posted May 5, 2007 You can work that out with Assign() and Eval() but that is ALWAYS a bad idea compared to simply learning to use arrays. You don't want to kludge together variable names, you want an array:#include <array.au3> Global $Skill[1] = [0] For $n = 1 to 10 _ArrayAdd($Skill, "Skill number " & $n) Next $Skill[0] = UBound($Skill) -1 _ArrayDisplay($Skill, "Skill list")You can address the skill list above as $Skill[1] thru $Skill[10]. The first element in the array, $Skill[0], contains the count. You don't have to know how many there will be ahead of time. 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now