Division

1. Senior Member
Join Date
Dec 1969
Posts
195

## Division

How would I do something like this:<BR><BR>If totalNumber is divisable by 3 then<BR><BR>???<BR><BR>Basically, I want to take the totalNumber of records returned and placing a certain amount of them on a page at once according to the lowest number they can be divisable by.<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Do you mean...

... *evenly* divisible?<BR><BR>If so:<BR><BR>&#060;%<BR>If totalNumber MOD 3 = 0 Then ...<BR>%&#062;<BR><BR>But then you went on to say..."according to the lowest number they can be divisable [sic] by."<BR><BR>Ummm...the lowest number they can be divisible by is *always* 1!<BR><BR>Would you care to explain a bit more??? I really can&#039;t make sense of what you said, there.<BR><BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
195

## RE: Do you mean...

Sorry about that...<BR><BR>I&#039;ve never been good at math, so you can imagine the challenge I&#039;m getting out of coding.<BR><BR>Okay, originally I was trying to display results where if the last page had only 4 or less results, I wanted them to be added to the previous page instead. <BR><BR>I figured that a better way to go about this is to find the total number of results returned and then if they are divided by a certain number to simply display a specified amount per page.<BR><BR>Did I say "simply"?<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
195

## RE: Do you mean...

Think of it like a wrestling event card.<BR><BR>The fans need to get their money&#039;s worth so you can&#039;t have four matches a card. There has to be AT LEAST five, but no more than eight.<BR><BR>This is similar to the output I&#039;m trying to accomplish.<BR><BR>But then there&#039;s this problem -<BR>What if there&#039;s one match left over in the equation? How do I say, "Blah, I&#039;ll just tack it onto the last card".<BR><BR>Hrm...<BR><BR><BR><BR><BR><BR><BR><B R>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Go with original scheme...

Let&#039;s see... <BR><BR>Your target is (let&#039;s say) *no more than* 10 records per page. <BR><BR>So you do something like this:<BR>&#060;%<BR>For recPerPage = 10 To 1 Step -1<BR>&nbsp; &nbsp; If recordCount MOD recPerPage = 0 Then Exit For<BR>Next<BR>RS.PageSize = recPerPage<BR>%&#062;<BR><BR>Sounds nice in theory, yes?<BR><BR>Try it with 49 records. You&#039;ll get 7 records per page.<BR>Try it with 48 records. You&#039;ll get 8 records per page.<BR>Try it with 51 records. You&#039;ll get...oops...THREE (3) records per page.<BR><BR>But wait...<BR><BR>Try it with 53 records. You&#039;ll get ONE (1) SINGLE RECORD per page.<BR><BR>Ever heard of "prime numbers"? Those are numbers that are *ONLY* divisible by themselves and one.<BR><BR>Want the first few "prime numbers"? Let&#039;s see...<BR><BR>1,2,3,5,7,11,13,17,19,23,29,31,37,41 ,43,47,53 ...<BR><BR>Want to take a chance on *not* getting a prime number of records?<BR><BR>No? I didn&#039;t think so.<BR><BR>Go back to "If less than N records, toss them onto last page." If nothing else, your users will understand it better.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
195

## Groovy... Thanks. <eom>

...

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Oh, that part is easy!

Back to the MOD operator!<BR><BR>&#060;%<BR>Dim recordCount, pageCount, leftOver, addToLastPage<BR><BR>recordCount = xxx &#039; get this from somewhere<BR><BR>pageCount = recordCount recordsPerPage &#039; integer division!<BR>leftOver = recordCount MOD recordsPerPage <BR><BR>&#039; (arbitrary: tack less than half a page onto prior page)<BR>If leftOver &#062;= (recordsPerPage/2) Then<BR>&nbsp; &nbsp; pageCount = pageCount + 1<BR>&nbsp; &nbsp; addToLastPage = 0<BR>Else<BR>&nbsp; &nbsp; addToLastpage = leftOver<BR>End If<BR>...<BR>%&#062;<BR><BR>Then, when you are displaying the records:<BR><BR>&#060;%<BR>recordsThisPage = recordsPerPage<BR>If pageNumber = pageCount Then<BR>&nbsp; &nbsp; recordsThisPage = recordsThisPage + addToLastPage<BR>End If<BR><BR>startRec = (pageNumber-1) * recordsPerPage<BR>For recNum = startRec To startRec + recordsThisPage - 1<BR>&nbsp; &nbsp; ... display record number recNum ...<BR>Next<BR>...<BR>%&#062;<BR>

#### Posting Permissions

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