3 Replies Latest reply on Apr 20, 2015 5:26 AM by schpa

    Grab value from a dynamically named variable.



      Grab value from a dynamically named variable.


      So I've been using a script from a source I can't seem to find again, but basically, it's an OnLayoutLoad script that gathers the visited layouts in a $$Stack variable and the currently viewed layout from this stack in a $$Number variable used to navigate back and forth between layouts just like in a web browser, a very handy little function.

      Now, the problem with it is that it's stored globally in the whole file, so if I were to open up a new window and visit other layouts in that window, this would add to this stack and the navigation would be between the layouts visited in the former layout aswell. For me, this is a bit chaotic and confusing for the consumer, and I would therefore like to make a seperate $$Stack and $$Number variable to each window. The way I've done this is be using the custom function fnSetGlobalVar to store the calculations in a dynamic variable $$Stack & Get ( WIndowName ). However, the problem is that the calculations also requires the value from the $$Stack and it doesn't work to just grab the data from  ( $$Stack & Get ( WindowName ) ) as that just leaves me with the value in the $$Stack variable and the window name, which just messes the whole script up and does not work.

      To solve this, I've been trying to grab the data from, if the window name is say "Customers", with a local variable $stack with the value: $$Stack & Get ( WindowName ), but that just leaves me with the exact same thing, the value of the $$Stack and then the name of the window, in other words, it's useless in my case.

      Now, my question is; how do I go about acquiring the data from the dynamically named variable without having to do an if or case evalution for each and every window name? Is it even possible?

      To make it clearer, if the Get ( WindowName) = "Customers" I want to calculate with/get the values from the global variable $$StackCustomers and $$NumberCustomers with a variant of 

      Set Variable [$Stack; Value; $$Stack & Get ( WindowName )]
      and the equivalent for $Number

      that actually leaves me with $$StackCustomers and not the data in $$Stack and then the window name, so to speak, hehe.

      I've been searching for a way to do this for hours but couldn't find a reasonable solution so I beg the experts of this forum for some very needed help :)

      Hope this wasn't too confusing and thanks for your attention.


        • 1. Re: Grab value from a dynamically named variable.

          Hi Simen,


          This is just a suggestion.  I have not worked through all its implications so take it with a grain of salt…

          When each new window is opened, it is standardly named "… - 2",  "… - 3",  etc.  Consider using something like GetAsNumber( RightWords( Get( WindowName ) ; 1 ) ) to obtain a window '$$Index' number ( 2,  3, etc.). Note: You will have to test for the primary window since it will probably be null in which case it should be set to 1.  

          This window '$$Index' can serve as the stack repetition number: $$Stack[ $$Index ] and $$Number[ $$Index ].  This effectively separates the navigation by window.




          • 2. Re: Grab value from a dynamically named variable.

            I like Jade's suggestion but to answer the original question:

            Evaluate ( "$$Stack" & Get ( WindowName ) )

            Should do what you want here.

            1 of 1 people found this helpful
            • 3. Re: Grab value from a dynamically named variable.

              Yea, that's not a bad idea Jade, I'll try to implement that :)
               As for what I originally wanted, Phil's answer what I was looking for, so thanks to the both of you!