Sign in to follow this  
Followers 0
willie_g_homie

Referencing alike variables in loops

6 posts in this topic

#1 ·  Posted (edited)

Hello,

new to Autoit. Have done the following in VB and VBA so know it can be done. question is how does Autoit syntax do it???

Want to reference any number of similar variables in for loop. i.e.

; example from VBA: ptv = varint(r("PT" & s))

Func fSetGUIbyINI()

Local $Trax, $Step, $STR = ""
Local $ArrayRow = 0
Const $NumOfTrax = 4; remove after testing
Const $NumOfStep = 13;  "        "     "
Local $TraxNumber[$NumOfTrax] = [1, 2, 3, 4]
Local $TraxLetter[$NumOfStep] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"]

  $intMaxSteps = $NumOfStep * $NumOfTrax
 
  For $Step = 0 to UBound($TraxNumber,1) - 1
    For $Trax = 0 to UBound($TraxLetter,1) - 1
      $STR = "$Trk"  & $TraxNumber[$Step] & "Compl" & $TraxLetter[$Trax]; <-problem
      GUICtrlSetState($STR, _iif($ATrax_Steps[$ArrayRow][2], $GUI_CHECKED, $GUI_UNCHECKED)) 
      $ArrayRow += 1
    Next
  Next
EndFunc
Edited by willie_g_homie

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the forums....

I cannot find an Autoit error on this line

$STR = "$Trk" & $TraxNumber[$Step] & "Compl" & $TraxLetter[$Trax] ; <-problem

and this seems to pass the SciTE editors syntax check

#include <Misc.au3>
#include <GUIConstants.au3>


;Func fSetGUIbyINI()

Local $Trax, $Step, $STR = ""
Local $ArrayRow = 0
Const $NumOfTrax = 4 ; remove after testing
Const $NumOfStep = 13;    "         "       "
Local $TraxNumber[$NumOfTrax] = [1, 2, 3, 4]
Local $TraxLetter[$NumOfStep] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"]


  $intMaxSteps = $NumOfStep * $NumOfTrax

  For $Step = 0 to UBound($TraxNumber,1) - 1
    For $Trax = 0 to UBound($TraxLetter,1) - 1
      $STR = "$Trk"  & $TraxNumber[$Step] & "Compl" & $TraxLetter[$Trax]    ; <-problem
      ;GUICtrlSetState($Trk1Compla, _iif($ATrax_Steps[$ArrayRow][2], $GUI_CHECKED, $GUI_UNCHECKED))
      $ArrayRow += 1
    Next
  Next

;EndFunc

However, if

$STR = "$Trk" &...

where $Trk is a varaiable ( undefined in the scriplet ) then it would be

$STR = $Trk & $TraxNumber[$Step] & "Compl" & $TraxLetter[$Trax] ; <-problem

without the quotes(")

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Hmmm. Interesting.

Thanks for the welcome and quick response. ;)

In all fairness, i edited the script after you copied it. oops!

Compiling always works. but the action doesn't. i have several checkboxes i want to manipulate. i.e.:

$Trax1Compla = GUICtrlCreateCheckbox(..................

$Trax1Complb

$Trax1Complc

....

...

.. and so on.

so how do i use a string to reference these in a loop?

And "$Trax" is part of the GUI variable name as illustrated above. String concatenate rule aplies. The & operator for adding strings is said to be unambiguous since it's limited to performing the string concatenation even when the data types are not string. Basically, i wish to get this result:

; $STR = "$Trk"  & $TraxNumber[$Step] & "Compl" & $TraxLetter[$Trax]   
   ; or
  
  $STR = "$Trax1Compla"
  GUICtrlSetState($STR, _iif($ATrax_Steps[$ArrayRow][2], $GUI_CHECKED, $GUI_UNCHECKED))

However, if

$STR = "$Trk" &...

where $Trk is a varaiable ( undefined in the scriplet ) then it would be

$STR = $Trk & $TraxNumber[$Step] & "Compl" & $TraxLetter[$Trax] ; <-problem

without the quotes(")

8)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

maybe..

Dim $Trax1Comp[4]
$Trax1Comp[1] = GUICtrlCreateCheckbox(..................
$Trax1Comp[2]
$Trax1Comp[3]
....

for $x = 1 to UBound($Trax1Comp) -1
    GUISetState($Trax1Comp[$x], $GUI_CHECKED)
next

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Looks good. should've thought of that. haste make waste.

thanks.

maybe..

Dim $Trax1Comp[4]
$Trax1Comp[1] = GUICtrlCreateCheckbox(..................
$Trax1Comp[2]
$Trax1Comp[3]
....

for $x = 1 to UBound($Trax1Comp) -1
    GUISetState($Trax1Comp[$x], $GUI_CHECKED)
next

8)

Share this post


Link to post
Share on other sites

Welcome...

I can see you have a great ability/knowledge of programming

in fact i had never seen _iif() before

.... Look forward to great stuff from you

8)


NEWHeader1.png

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