Deal with Multidimensional Array

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Deal with Multidimensional Array

Post by htuser »

Dear Cspro Developer Team,
I would like deal with multidimensional array in Cspro logic for replacing lot of if..then..elseif with more concise code.
Assumming that i have this array:

Code: Select all

array string tesArray(5,3) =
     "YKY", "S1","1",
     "ABC", "S2","2",
     "UJO", "S3","3",
     "LOP", "S4","4",
     "VGY", "S5","5";
Please can you explain me how to loop only in one column, the first by example to find a specific value?
Assuming that i have two items :
Item1 and Item2
How to fill Item2 with S1 if item1=1 and so on?

I find some good explanations on https://overiq.com/c-programming-101/tw ... rray-in-c/
and https://processing.org/tutorials/2darray/
about dealing with array in C. But, until now, i can't find a way to transpose theses explanations to Cspro Logic.
My first idea is to loop using Cspro's substring expressions but it's not appropriate for array and i don't find how to identify:
numeric i to line and numeric j to column...
Thanks in advance for your support.
G.VOLNY, a CSProuser from Haiti, since 2004
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Deal with Multidimensional Array

Post by htuser »

This exercice has been solved using undocumented (but Greg explain me a few months ago how to use them in array) tblrow and tblcol and C approach.
Best Regards,
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Deal with Multidimensional Array

Post by Gregory Martin »

I'm not sure what you're trying to do, but code like this should work:
do numeric row_counter = 1 while row_counter <= length(tesArray, 1)

    if ITEM1 = tesArray(row_counter, 2) then
        ITEM2 = tesArray(row_counter, 3);
        break;
    endif;

enddo;
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Deal with Multidimensional Array

Post by htuser »

Thank you Greg.
I've solved the test. I used tblrow(tesArray) instead of length(tesArray, 1), but doesn't using the break. I'm adding break.
With your example, i've more way and this allow me to have lest if then else. My applications are more powerful and dynamic.

But, i would also like to receive ideas from you for:
1.- Transform check box responses to array;
2.- Concatenation of multiples array. In javascript, it's very easy: https://stackoverflow.com/questions/508 ... e-n-arrays
I already send an email about this topic.
Best Regards,
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply