[thelist] One for the GURU's asp loop

Brooking, John John.Brooking at sappi.com
Mon May 2 07:10:34 CDT 2005


Brian Delaney wrote:
>I have a recordset that contains company 
>name,addr,addr1,city,state,zip
>
>I am trying to format the asp output so labels can be 
>printed. I am close using a style sheet and some margin 
>tweaking.
>
>I need to write the records 3 companies per row:
> <snip/>

Actually, here's a solution that will work in just about any language,
although I'll give the example in ASP syntax. Just keep a variable to
count the records, starting from 1, and use the Mod operator with an
operand of 3 to find out when you're at the end of an output row. The
Mod (modulus) function returns the remainder of dividing the first
argument by the second. So whenever the return value is 0, you know
you've reached the end of a label output row, and output the code to end
one row and start another.

Untested pseudo-code:

   row = 0
   ' Open your recordset
   ' Output start of label code, start of first row
   Do While Not myRecordSet.EOF
      ' output the current label
      row = row + 1
      If row Mod 3 = 0 Then 
         ' output code to end the current output row
         ' and start the new one
      End If
      myRecordSet.MoveNext()
   Loop
   ' Output end of current row, end of label set
   myRecordSet.Close()
   
This page[0] has a more detailed explanation of the modulus function,
and even a very similar example to what you're trying to do. By the way,
I've had trouble getting the GetRows() function to work, I never figured
out why. It might not be appropriate anyway if you've get a huge number
of records, although on the other hand, you probably don't have a huge
number of records if you're outputting them to mailing labels.

[0] http://www.asp101.com/articles/steven/mod/default.asp

- John
-- 


This message may contain information which is private, privileged or confidential and is intended solely for the use of the individual or entity named in the message. If you are not the intended recipient of this message, please notify the sender thereof and destroy / delete the message. Neither the sender nor Sappi Limited (including its subsidiaries and associated companies) shall incur any liability resulting directly or indirectly from accessing any of the attached files which may contain a virus or the like.



More information about the thelist mailing list