Topic: Concatenate the name of a variable - dynamic Posted: 28 Sep 2011 at 5:11pm
Good night.
I have the need of declaring a lot of shared variables. I have a report that is sorted/grouped by dates, I have a formula field there that shows a percentage for the specific date and obviously this calculation is repeated at every single date showing different percentages for each date/row.
I need a new variable created each time the calculation is done (at a subreport) for me to be able to catch each of those variables/percentages separately (at the main report).
I know how to get variables from a sub report to the main report, the problem is that when I declare the variable at the formula field at the sub report it doesn't give me a different variable for each day, instead I assume it is reseting the variable at each line that is generated and giving me the las value assigned to the variable.
Once, at a differente language, I found a function (that I don't remember) that made a concatenated text to be treated as a variable, it was something like:
(Let's assume the function I don't remember was called Variable)
i = 1
Variable("abc" i "efg") = i
That would have result in getting a variable with the name abc1efg which would have been equal to 1 and you could have use it anywhere else at the script. There is something very similar that I used once when creating a loop at an excel macro, however, again I don't remember the function and I have not been able to find that old file to refresh my memory.
I need something like that to be able to concatenate the variable name to make it dynamic by adding for example the date of the row being generated, that way instead of having the same variable set and reset over and over again, I will be getting a different variable each time one line of the report is generated.
for example, taking the previous example on account, something like:
(Assuming table.date is the database table field used for the dates at the sub-report)
Variable("abc" {table.date})
...which for each line should set/declare a different variable like the ones that follow: abc01sep2011, abc02sep2011, abc03sep2011, etc...
I want to state that I'm working with tables from 2 different databases with similar information, but different structure, and that's why I'm trying to get the info correctly processed into one single report by using sub reports and variables.
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Posted: 30 Sep 2011 at 4:00am
to the best of my knowledge, CR doesn't let you declare variable like that.
what would probably be simpler is to have 2 arrays running, one for the value and 1 for the name or however you want to reference it. CR only allows 1-d arrays, hence the multiple arrays. You can share the array as well, and they can grow using 'redim preserve'. I haven't used arrays much, and not in CR as I haven't found the need, so I am by no means an expert.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum