Is there a way to dynamically build a reference to a container (local variable)

I am looking for a way to dynamically build a reference to set of local variables that only differentiate by a number at the end.  Is this even possible? I haven't found a way and hope someone knows of a solution.  I would really like to write some flexible code here if possible.  

local variables
ap1
ap2 
ap2

repeat 3 times
  put reference of ap&counter() into staging  //puts 1
  log ap&counter()  //doesn't work.  Logs 'ap1' not the value of ap1
  log staging  // logs 1 
end repeat

Comments

  • cliss1974cliss1974 Member
    I didn't find a way to do this but in reading around the documentation I decided to approach it a different way.  Its kinds of hacky but let me know what you think.  My workaround involves using a "list" and some key works that allow you to access the list. 

    ===code===
    put ap1 into problemList
    insert ap2 into problemList
    insert ap2 int problemList

    repeat 3 times
      log item Counter() of the problemList  //correct value is referenced each time.
    end repeat
  • DaveHesterDaveHester Member
    Here is another option. BTW, name1...name3 can be row headers in Excel.
    set apple.name1 to "Gala"
    set apple.name2 to "Red Delicious"
    set apple.name3 to "Golden Delicious"
    set counter to 1
    repeat 3 times
    log apple.("name"&counter)
    set counter to counter + 1
    end repeat
Sign In or Register to comment.