Follow via:
RSS
Email Alert
Question
0 Votes
+ -

Array Output Sorting Issue

Hello. First of all I'm programming in VB.NET/ASP.NET doing a page for a website. Now, to my question....

I have a simple array of integer numbers (15 characters in length) which can hold up to 2000 items. What I basically need to do is output these numbers to a PDF file I'm creating on the fly and I can only fit a certain amount of numbers per page. What I need to do is just output these on each page in numerical order vertically NOT horizontally. Based on page size restrictions, the amount of numbers I can output per page is 19 rows x 7 columns (or 133 items total).

Now, I already have the PDF creation going fine, including adding more pages as there's more numbers being added, etc. It's just the sorting of these numbers that I'm outputting I'm having trouble with. What I'm doing currently (which is archaic), since I can only output horizontally at the moment, is outputting the first number, then skipping the next 18, and then outputting the next number, then skipping the next 18, etc. Once I get to the 7th number (1st row, 7th column), I output it, skip backwards to the 2nd number in the array, and output it as I'll now be in the 2nd row (2nd row, 1st column). I keep doing this until all numbers in the array are output. The only problem is that, other than being finicky and definitely not an efficient way of doing it, is if the array has fewer than 133 numbers (or if by chance there's fewer than 133 numbers on any one page), the output structure is all messed up.

For more info on what I'm currently doing, here's some code examples:

[code]
Dim theTagArray(2000) As String
' theTagArray is filled before this next section...

Dim thecount2 As Integer = 0
Dim thecount3 As Integer = 0
Dim thenum As Integer = 19
' Nice mess to print tags in numeric order down each column, left to right...
' Basically, start with first element, then skip 18 and put next, skip 18 put next, etc. and so forth...
' pdfText2a.Add is the function that's basically outputting the array element... to the PDF...
If thecount3 = 7 Then
thecount2 += 1
thecount3 = 0
pdfText2a.Add(theTagArray(thecount2 + (thecount3 * thenum)) & " | ")
thecount3 += 1
Else
pdfText2a.Add(theTagArray(thecount2 + (thecount3 * thenum)) & " | ")
thecount3 += 1
End If
[/code]

I want it to look kind of like this:


982000018301450 | 982000018561709 | ...
982000018561265 | 982000018561724 | ...
...



Though 7 across, 19 down.

So, this is why I'm asking if there's a way to output an array vertically instead of horizontally in either a slightly more efficient way than I'm doing it, or by using a much better method altogether. Please help if you can. Thanks for your help.
24th Mar 2008

Answers (1)

0 Votes
+ -
Well if I understood
You want the first 133 numbers on page 1 , the next on two etc
And you want on each page 7 columns of 19 numbers, the first 19 in column 1, the next in column two etc .

But because you are outputing horizontally you need to do numbers
1,20, 39, 58, 77, 96, 115 on the rirst row.

Personally I'd copy the array into the order I wanted to output it.

In pseudo code
printarray = new array[numberofitems]

rowsperpage = 19
columnsperpage = 7
itemsperpage = rowsperpage * columnsperpage

loop from 0 to numberofitems - 1

page = loop div itemsperpage

pageoffset= (page * itemsperpage)

column = (loop - pageoffset) div rowsperage

columnOffset = column * rowsperpage

row = item - pageoffset - columnoffset

printarray[pageoffset+columnoffset+row] = array[loop]

Printing should be a piece of cake now and you don't have all this in your print routine.

div is integer division, 134 div 133 = 1
If you dont / can't have div do it in floating point and truncate / convert to int

You could forget the sort and then print idea and do it all in one, but if you get something similar to do you'll be repeating code.

Not to mention that you will be having to comment it to death or puzzle the heck out of yourself or an other devloper in six months time.

HtHs

Edited because I got row and column div bum about face.
Updated - 24th Mar 2008
Answer the question
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.