DEV Community

Peter + AI
Peter + AI

Posted on

Uniface Quick Tip: Taming Your Print Layouts with $totlines πŸ“„

Hey Uniface developers! πŸ‘‹ Ever found yourself wrestling with report layouts, trying to prevent an important chunk of data from splitting awkwardly across two pages? It's a classic problem. Today, we're looking at a simple but super useful ProcScript function that can help: $totlines.

(Quick heads-up: This post was drafted with the help of an AI assistant to break down the official Uniface 10.4 documentation into a simple, easy-to-read format!)

What Exactly is $totlines? πŸ€”

In simple terms, $totlines tells you the total number of lines available for printing on the current page. The key thing to remember is that this number excludes any space reserved for header and footer frames. It's the pure "body" area of your page.

The function is straightforward:

  • If you are currently printing (meaning $printing is 1), $totlines will return a number greater than 0, representing the total lines.
  • If you are not in print mode, it returns 0.

Practical Examples πŸš€

Theory is great, but let's see how you can actually use it. Here are two common scenarios based on the Uniface docs.

Example 1: Finding Your Current Line Number πŸ—ΊοΈ

Sometimes you need to know exactly which line you are about to print on. You can calculate this by combining $totlines with the $lines function (which tells you how many lines are left* on the page).

_


; Calculate the current line number
vLineNum = ($totlines - $lines)
Enter fullscreen mode Exit fullscreen mode

Simple, right? By subtracting the remaining lines from the total lines, you get the current line number you're on.

Example 2: Checking if an Entity Fits on the Page 🧱

This is a lifesaver! Imagine you have an entity occurrence (like a customer's order details) that you want to keep on a single page. You can use $totlines in the "LeavePrinted" trigger to check if it will fit before it gets printed.


trigger LeavePrinted 
 ; Check if the depth of the frame is more than the total lines available
 if (($totlines - $framedepth) < 0)
  ; If it doesn't fit, print a message
  putmess "%%$entname didn't fit on 1 page: see page %%$page."
 endif
end
Enter fullscreen mode Exit fullscreen mode

Here, $framedepth gives you the number of lines the entity needs. If the available lines are less than what's needed, the code triggers a message. This allows you to handle the overflow gracefully instead of just letting it break apart.

Key Takeaways ✨

While $totlines is a small function, it's a great tool for gaining control over your Uniface reports. By using it with other functions like $lines, $framedepth, and $printing, you can create much cleaner and more professional-looking printouts.

Happy coding! πŸŽ‰_

Top comments (0)