' Address label printing with XPRINT positioning via DECLARE
#COMPILE EXE
#DIM ALL

%LABEL_W = 288
%LABEL_H = 144
%COLS = 3
%ROWS = 7

FUNCTION LabelX(BYVAL col AS LONG) AS LONG
    FUNCTION = 18 + col * %LABEL_W
END FUNCTION

FUNCTION LabelY(BYVAL row AS LONG) AS LONG
    FUNCTION = 18 + row * %LABEL_H
END FUNCTION

SUB PrintAddr(BYVAL labelNum AS LONG, BYVAL name AS STRING, BYVAL street AS STRING, BYVAL city AS STRING, BYVAL state AS STRING, BYVAL zip AS STRING)
    PRINT "Label #"; labelNum; ":"
    PRINT "  "; name
    PRINT "  "; street
    PRINT "  "; city; ", "; state; " "; zip
END SUB

SUB PrintGrid()
    PRINT ""
    PRINT "Label grid: "; %COLS; " x "; %ROWS; " = "; %COLS * %ROWS; " per sheet"
    LOCAL r  AS LONG
    LOCAL c  AS LONG
    FOR r = 0 TO %ROWS - 1
        FOR c = 0 TO %COLS - 1
            PRINT "  ("; c; ","; r; ") at ("; LabelX(c); ","; LabelY(r); ")"
        NEXT c
    NEXT r
END SUB

SUB BatchLayout()
    PRINT ""
    PRINT "Sample addresses:"
    PrintAddr(1, "John Doe", "123 Main St", "Springfield", "IL", "62701")
    PrintAddr(2, "Jane Smith", "456 Oak Ave", "Portland", "OR", "97201")
    PrintAddr(3, "Bob Wilson", "789 Pine Rd", "Austin", "TX", "73301")
    PrintAddr(4, "Alice Brown", "321 Elm St", "Denver", "CO", "80201")
    PrintAddr(5, "Charlie Davis", "654 Maple Dr", "Seattle", "WA", "98101")
    PrintAddr(6, "Diana Evans", "987 Cedar Ln", "Boston", "MA", "02101")
END SUB

SUB GridAssignment()
    PRINT ""
    PRINT "Grid assignments:"
    LOCAL i AS LONG
    FOR i = 1 TO 6
        LOCAL col  AS LONG
        LOCAL row  AS LONG
        col = (i - 1) MOD %COLS
        row = (i - 1) / %COLS
        PRINT "  Label "; i; " -> col="; col; " row="; row
        PRINT "    pos=("; LabelX(col); ","; LabelY(row); ")"
    NEXT i
END SUB

SUB AveryInfo()
    PRINT ""
    PRINT "Avery 5160: 2.625 x 1 inch, 3x10=30/sheet"
END SUB

FUNCTION PBMAIN() AS LONG
    PRINT "=== Label Print Demo ==="
    BatchLayout()
    PrintGrid()
    GridAssignment()
    AveryInfo()
    PRINT "=== End Label Print ==="
    FUNCTION = 0
END FUNCTION
