Jump to content

Referencing alike variables in loops


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
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)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...