Results 1 to 4 of 4

Thread: Calculating Total Pages - Whole Numbers Question

  1. #1

    Thread Starter
    Member
    Join Date
    May 2004
    Location
    Huntington WV
    Posts
    49

    Calculating Total Pages - Whole Numbers Question

    I am stuck on this algorithm and not quite sure how to approach it. My program needs to calculate the number of pages prior to sending it out to the printer. I know that I can use printer.page to get the page number but I need the total pages printed on the cover page. Here is what I have.

    The number of records per page is set at 8. So each page contains no more than 8 records. I can get the record count by table1.recordset.recordcount, so I can get the total records. The problem is this.

    If I make dTotalPages = table1.recordset.recordcount / 8 and the total records are not divisible by 8 the iTotalPages would contain a fraction if it was a double instead of an integer. So for instance if the record count is 9 then the iTotalPages = 1 So the output would produce 2 pages, 8 on the first page and 1 on the second page. So the dTotalPages should equal 2.

    Here is what I have tried.

    VB Code:
    1. dim iTotalPages as Integer
    2. dim dTotalRecords as Double
    3. dim X as Double
    4. dim Y as Integer
    5.  
    6. 'dTotalRecords = table1.recordset.recordcount 'commented out for testing
    7. dTotalRecords = 9
    8.  
    9. If dTotalRecords < 1 then
    10.     iTotalPages = 1
    11. Else
    12.     iTotalPages = dTotalRecords / 8
    13.     X = val(right(dTotalPages, 4))
    14.           if X > 0 then
    15.              X = 1
    16.           End If
    17.     Y = iTotalPages 'only gets the whole number
    18.     iTotalPages = X + Y
    19. End If

    The resulte is still 1 page and should be 2 pages in this test.
    Last edited by MIKEADKINS; Dec 30th, 2005 at 09:45 AM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Calculating Total Pages - Whole Numbers Question

    try this instead:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim iTotalPages As Integer
    5.  
    6.     iTotalPages = CalcTotalPages(9, 8)
    7.     MsgBox "Total Pages: " & iTotalPages
    8.  
    9. End Sub
    10.  
    11. Public Function CalcTotalPages(iTotalRecords As Integer, iRowsPerPage As Integer)
    12. Dim iTotalPages As Integer
    13.  
    14.     iTotalPages = iTotalRecords / iRowsPerPage
    15.     If iTotalRecords Mod iRowsPerPage > 0 Then
    16.         iTotalPages = iTotalPages + 1
    17.     End If
    18.     CalcTotalPages = iTotalPages
    19.  
    20. End Function

  3. #3
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Calculating Total Pages - Whole Numbers Question

    How about...

    x = dTotalRecords mod 8

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width