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, "HELLO WORD", 4];
ForEach (a$, i$)
* if (mtype(i$) == ET_STRING)
*** ShowMessage(@i$ % " " % mtype(i$));
* else
*** ShowMessage(i$ % " " % mtype(i$));
* end;
end;
ShowMessage("MCount = " % mcount(a$, true));
ShowMessage("MType = " % 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("MCount = " % mcount(a$, true)); // Value is 10
ShowMessage("MCount = " % mcount(a$, false)); // Value is 4
ShowMessage("MType = " % MType(a$[1])); // Value is 3 ET_MATRIX</p>
a$ = [1, 2, "HELLO WORD", 4];
ForEach (a$, i$)
* if (mtype(i$) == ET_STRING)
*** ShowMessage(@i$ % " " % mtype(i$));
* else
*** ShowMessage(i$ % " " % mtype(i$));
* end;
end;
ShowMessage("MCount = " % mcount(a$, true));
ShowMessage("MType = " % 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("MCount = " % mcount(a$, true)); // Value is 10
ShowMessage("MCount = " % mcount(a$, false)); // Value is 4
ShowMessage("MType = " % MType(a$[1])); // Value is 3 ET_MATRIX</p>