' Multi-page report with headers, page numbers via XPRINT DECLARE
#COMPILE EXE
#DIM ALL

%LINE_H = 14
%MAX_PER_PAGE = 10

SUB PrintPageHeader(BYVAL page AS LONG, BYVAL total AS LONG)
    PRINT "System Health Report"
    PRINT "Generated by PBXB64"
    PRINT "2026-06-03  Page: "; page; " of "; total
    PRINT "------------------------------------------"
    PRINT LEFT$("Name" + SPACE$(25), 25)
    PRINT LEFT$("Value" + SPACE$(15), 15)
    PRINT "Status"
    PRINT "------------------------------------------"
END SUB

SUB PrintPageFooter(BYVAL page AS LONG)
    PRINT "------------------------------------------"
    PRINT "Confidential | Internal Use Only"
    PRINT "Page "; page
END SUB

SUB PrintReportLine(BYVAL name AS STRING, BYVAL value AS STRING, BYVAL status AS STRING)
    PRINT LEFT$(name + SPACE$(25), 25)
    PRINT LEFT$(value + SPACE$(15), 15)
    PRINT status
END SUB

SUB PrintReport(BYVAL pages AS LONG)
    LOCAL p  AS LONG
    LOCAL startRow  AS LONG
    FOR p = 1 TO pages
        PrintPageHeader(p, pages)
        startRow = (p - 1) * %MAX_PER_PAGE
        IF startRow = 0 THEN
            PrintReportLine("System Uptime", "14 days 3h", "OK")
            PrintReportLine("CPU Usage", "23%", "OK")
            PrintReportLine("Memory Usage", "67%", "WARNING")
            PrintReportLine("Disk C:", "45% used", "OK")
            PrintReportLine("Disk D:", "89% used", "CRITICAL")
            PrintReportLine("Network Throughput", "45 Mbps", "OK")
            PrintReportLine("Active Connections", "23", "OK")
            PrintReportLine("Error Rate", "0.01%", "OK")
            PrintReportLine("Queue Depth", "3", "OK")
            PrintReportLine("Response Time", "45ms", "OK")
        END IF
        IF startRow = 10 THEN
            PrintReportLine("Battery Level", "76%", "OK")
            PrintReportLine("Temperature", "42C", "WARNING")
        END IF
        PrintPageFooter(p)
    NEXT p
END SUB

SUB PaginationCalc()
    LOCAL totalData  AS LONG
    LOCAL totalPages  AS LONG
    totalData = 12
    totalPages = (totalData + %MAX_PER_PAGE - 1) / %MAX_PER_PAGE
    PRINT ""
    PRINT "Pagination:"
    PRINT "  Data lines: "; totalData
    PRINT "  Max/page: "; %MAX_PER_PAGE
    PRINT "  Pages: "; totalPages
END SUB

FUNCTION PBMAIN() AS LONG
    PRINT "=== Report Print Demo ==="
    PrintReport(2)
    PaginationCalc()
    PRINT "=== End Report Print ==="
    FUNCTION = 0
END FUNCTION
