Announcement

Collapse
No announcement yet.

PageCount

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PageCount

    If I want to break some text into pages, I use this to figure out the expected page count...

    There's only the 2 lines that do the calculations. But it seems like there ought to be a simpler calculation to get PageCount - more minimal!

    Code:
    Function PBMain() As Long
       Local PageCount, TotalLines, MaxLinesPerPage As Long
       TotalLines = 101
       MaxLinesPerPage = 25
    
       PageCount = TotalLines \ MaxLinesPerPage
       PageCount +=  IIf(PageCount* MaxLinesPerPage < TotalLines, 1,0)
    
       ? Str$(PageCount)
    End Function

  • #2
    I guess this counts as a more minimal solution ... there's no intermediate value for PageCount...

    Code:
    PageCount = TotalLines \ MaxLinesPerPage + IIf( TotalLines Mod MaxLinesPerPage,1,0)

    Comment


    • #3
      Hey Gary!

      How about PageCount = CEIL(TotalLines / MaxLinesPerPage) ?

      CEIL: Convert a floating point variable or expression into an integral class value, by returning the smallest integral value that is greater than or equal to its argument.

      Comment


      • #4
        Howdy, Pierre!

        Well now, that's the kind of minimal I'm talking about. You can count on 1 hand the number of times I've used it. Thanks!

        Comment


        • #5
          CEIL is your friend

          PageCount = CEIL(TotalLines /MaxLinesPerPage)

          Edit: I see Pierre beat me to it

          Comment


          • #6
            Just pulled up a bit of old code where the first page has fewer lines. There are lots of ways you could expand on it if needed:

            NoOfLines = NoOfLines - %FirstPageLines
            PageCount = 1
            If NoOfLines >0 THEN PageCount = 1 + CEIL(NoOfLines / %SubsequentPageLines)

            Comment


            • #7
              This what I use , work fine

              LOCAL LRSLT, I, I2, v_CTpx, hFont, nFile, cM, bmX, bmY, ncWidth, ncHeight, Tp1 AS LONG
              LOCAL H, W, P, X2, Y2, GT,IT AS SINGLE
              LOCAL T0, T1, T2,T3, sFile AS STRING, IV AS INVT, modRslt AS INTEGER

              'number of pages to print , MOD returns remainder between two numbers '<<<< count code start here
              modRslt = (MANR*6) MOD 54
              IF modRslt=0 THEN
              tP=(MANR*6) / 54 '54 = 9 lines * 6 records per page, if 0 even divide not reminder
              ELSE
              tP= INT((MANR*6) / 54) + 1 ' if not 0 , int no. of recs + 1
              END IF

              NUM=1: nP=1: ToDo_PrtAll_Print_GText '<<<<< count code ends here goes to print preview and select to print


              (MANR=NUMBER OR RECORDS IN DATA FILE)
              Robert

              Comment


              • #8
                Originally posted by Robert Alvarez View Post
                This what I use , work fine

                LOCAL LRSLT, I, I2, v_CTpx, hFont, nFile, cM, bmX, bmY, ncWidth, ncHeight, Tp1 AS LONG
                LOCAL H, W, P, X2, Y2, GT,IT AS SINGLE
                LOCAL T0, T1, T2,T3, sFile AS STRING, IV AS INVT, modRslt AS INTEGER

                'number of pages to print , MOD returns remainder between two numbers '<<<< count code start here
                modRslt = (MANR*6) MOD 54
                IF modRslt=0 THEN
                tP=(MANR*6) / 54 '54 = 9 lines * 6 records per page, if 0 even divide not reminder
                ELSE
                tP= INT((MANR*6) / 54) + 1 ' if not 0 , int no. of recs + 1
                END IF

                NUM=1: nP=1: ToDo_PrtAll_Print_GText '<<<<< count code ends here goes to print preview and select to print


                (MANR=NUMBER OR RECORDS IN DATA FILE)
                How does that differ from the simpler:
                Code:
                modRslt = MANR MOD 9
                IF modRslt=0 THEN
                    tP=MANR/9      
                ELSE
                   tP= INT(MANR/9) + 1
                END IF
                or
                Code:
                tP = CEIL(MANR /9)

                https://forum.powerbasic.com/forum/u...569#post792569

                Comment


                • #9
                  The sample I showed was a little more complex. It had a picture with so many lines of text per picture. With just text it gets more simple.
                  Robert

                  Comment

                  Working...
                  X