PDA

View Full Version : How to effectively use matrix


kornalius
01-09-2007, 02:13 PM
Here is how to handle matrix with ForEach. This code will also show you how to find out the number of elements in a matrix and how to know the type of a matrix element:</p>

a$ = [1, 2, &quot;HELLO WORD&quot;, 4];
ForEach (a$, i$)
* if (mtype(i$) == ET_STRING)
*** ShowMessage(@i$ % &quot; &quot; % mtype(i$));
* else
*** ShowMessage(i$ % &quot; &quot; % mtype(i$));
* end;
end;
ShowMessage(&quot;MCount = &quot; % mcount(a$, true));
ShowMessage(&quot;MType = &quot; % MType(a$[2])); // value is 2 for ET_STRING</p>

a$ = [[1, 2, 3, 4], [5, 6, 7, 8], 9, 10];
ForEach (a$, i$)
* if (vartype(i$) == _MATRIX);
*** ForEach (i$, z$)
***** ShowMessage(z$);
*** end;
* else
*** ShowMessage(i$);
* end;
end;
ShowMessage(&quot;MCount = &quot; % mcount(a$, true)); // Value is 10
ShowMessage(&quot;MCount = &quot; % mcount(a$, false)); // Value is 4
ShowMessage(&quot;MType = &quot; % MType(a$[1])); // Value is 3 ET_MATRIX</p>