Hello OS-community,
how to write a ZPL-code printing elements of a single or multi-dimensioned array (ie. Array(i), Arrax(i,j)) in one line in the output of the text viewer?
Thanks
Hello OS-community,
how to write a ZPL-code printing elements of a single or multi-dimensioned array (ie. Array(i), Arrax(i,j)) in one line in the output of the text viewer?
Thanks
Hi Lieu-Kim,
There is an example in the Help File under: The Programming Tab > About the ZPL > Array Variables
I’m copying this example here for your reference:
DECLARE Z, DOUBLE, 2, 5, 5
FOR i, 1, 5, 1
FOR j, 1, 5, 1
Z(i, j) = i + j
NEXT j
NEXT i
FORMAT 8.0 k = 0
FOR i, 1, 5, 1
FOR j, 1, 5, 1
PRINT k, i, j, Z(i,j)
k = k + 1
NEXT j
NEXT i
RELEASE Z
The second half shows you how you can print the array.
Let me know if this helps, and take care,
David
Hi David,
many thanks for your suggestion, which I have already tried. Unfortunately this is not what I want to achieve.
The out put shows array components in a column but not in a row.
The out put should look like below:
Hi Lieu-Kim,
I would do the following:
DECLARE Z, DOUBLE, 2, 5, 5
FOR i, 1, 5, 1
FOR j, 1, 5, 1
Z(i, j) = i + j
NEXT j
NEXT i
result$ = ""
FORMAT 1.0
FOR i, 1, 5, 1
FOR j, 1, 5, 1
result$ = result$ + " " + $STR(Z(i,j))
NEXT j
NEXT i
PRINT result$
RELEASE Z
Which is basically, save an empty string, and add the number to be displayed to that string using the $STR() function. At the end, print the string.
Does that make sense?
Take care,
David
Hi David,
this is exactly what I need.
Thank you so much for your great help!
Hi David,
there is a problem with the size limit of string:
Syntax error: String exceeded maximum allowed length of 360 characters in expression.
What is to do?
Hi Lieu-Kim,
The maximum length of a STRING array is around 360 characters (it’s “around” 360 because the ZPL pre-processor manipulates a string and sometimes removes spaces or replaces a non-alphanumeric character with a unicode equivalent).
For printing an 2D array in a grid, you should simply have 2 FOR loops; the inner FOR loop will print the each column in the row and the outer FOR loop will move to the next line. For the inner FOR loop, you simply need to end the PRINT command with a comma:
FOR i = 1, 10, 1
FOR j = 1, 10, 1
PRINT $STR(Z(i, j), $TAB(),
NEXT
PRINT
NEXT
This time it works perfect as I wish.
Thank you very much, David
Well, you can thank
Though, if you can avoid having a print in a loop, it might be preferable.
Take care,
David
Thank you Michael for your great support
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.