Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assign values dynamically

Status
Not open for further replies.

swiss2007

Technical User
Aug 13, 2007
92
US
Hi All,
I have a series of Questions coming from the sql server database and I have to assign codes to these questions,but the problem is that the codes could be changing.
Is there a way to dynamically assign codes?
for ex:
Question Code
1 BZ could be AZ
2 BYX could be BCX
3 BZX could be ABX
Any help would be greatly appreciated.
Thanks in advance.
 
Are you manually assigning the codes to begin with? And then later they might change? You could set up an array in the report header that establishes the value of the codes in a variable that you can then reference in multiple places in the body of the report. Then if the values change, you only have to change the formula in the report header.

-LB
 
Hi lbass,
Thanks for your quick reply.
Yes,I am manually assigning the codes and actually I have got some 75 questions and some questions have multiple codes.
Could you please give me an example of declaring the variable and assigning the codes in an array so that I can use the array to assign codes to the Questions,take the above case for example.

Thanks
 
Let's say you had 5 questions. In the report header, you would add a formula like this:

whileprintingrecords;
numbervar array x;
numbervar i;
numbervar j := 5; //add in the number of questions here
stringvar array y := ["AB","ABC","BCD","DEF","KJL"];
//add as many codes as questions

for i := 1 to j do(
redim preserve x[j];
x := i;
);

Then in the body of the report you would check the number of the question in order to select the correct code from the array, as in:

whileprintingrecords;
numbervar array x;
stringvar array y;
numbervar i;
numbervar j;
stringvar z;

for i := 1 to j do(
if {Orders.Customer ID} = x then
z := y
);
z

The only thing you have to update then is the formula in the header--the number of questions and the codes.

-LB
 
Hi lbass,
Thanks for the solution and it took me a while to get back to you.
In an array,if I want to pick 6.A.g but not 6.A.g1 and 6.A.g2 - How do I do this.
I tried to use like "*6.A.g*" but it picks up 6.A.g1 and 6.A.g2.
And one more thing,I have 2 different offices-local and non local.A few Questions,I mean same questions have different codes in local and non local offices and these are distinguished in the database using local and lnon local offices.
Is it possible to assign codes differently to local and non local offices.
The solution you provided works absolutely fine if there was only one office.Thanks again

 
Don't use wild cards or "like". Just use = .

Try this:

whileprintingrecords;
numbervar array x;
numbervar i;
numbervar j := 5; //add in the number of questions here
stringvar array y1 := ["AB","ABC","BCD","DEF","KJL"];//localoffice1
stringvar array y2 := ["DB","DBC","DCD","DED","DJL"];//localoffice2

for i := 1 to j do(
redim preserve x[j];
x := i;
);

Then in the body of the report you would check the number of the question in order to select the correct code from the array, as in:

whileprintingrecords;
numbervar array x;
stringvar array y1;
stringvar array y2;
numbervar i;
numbervar j;
stringvar z;

for i := 1 to j do(
if {Orders.Customer ID} = x and
{table.localoffice} = "A" then
z := y1 else
if {Orders.Customer ID} = x and
{table.localoffice} = "B" then
z := y2
);
z

-LB
 
pretty much clear on the 2nd part.

for ex consider this scenario.

Record 1:

question code
-------- ----
1 AB,BCD
2 ABC,ABD
3 BCD
4 DEF,CAB
5 KJL
Record 2:

question code
-------- ----
1 AB,CAB
2 ACB
3 BCD
4 DAF
5 KJL

I need to count the number of questions that have AB code.
If I use a running total,count number of questions
and use a formula like code ="*AB*"
it picks AB,ABC,ABD,CAB but I want only the count of AB
I can use something like"AB*" but AB could be in the beginning or at the end.
so I want to use a formula that has only AB.
Thanks for the second portion.


 
stringvar array k := split({@code},",");
local numbervar i;
local numbervar j := ubound(k);
numbervar cntAB;

for i := 1 to j do(
if k = "AB" then
cntAB := cntAB + 1
);

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top