Design question: how to build a multi-column <table in Desktop

I have a simple problem, and my solution works… more or less…

Here’s the problem:

I scan a master folder looking for data. These data are saved in an html file.

At the start of the html document, I set an href table in four columns.

To achieve that, I cound the number of “valid” folders inside the master folder. This value is stored inside Total_Cnt. Because I want to store the references inside 4 columns, I created another variable to hold the number of entries in that table: Loc_Row = Ceil(Total_Cnt / 4).

In the data creation flow, I create and store the entries and increment a special variable Loc_Cnt. I have an If block to deal with the href links:

If Loc_Row = Row_Cnt Then // See (*) below
// Add a brand new Row
// Reset Loc_Row to 0
Else
// Increment the Loc_Row (# of Rows in each Column)
Loc_Row = Loc_Row + 1
End If

(*) Using > instead of = leads to troubles too depending on the Total_Cnt value. I tried >= too, but it is also troublesome.

Changing Ceil by Floor may lead to the creation of a 5th column.
As is (using >), the program, depending on the Total_Cnt value, may lead in errors too.
As a variation, I also noted 4 more rows in Columns 1, 2 and 3 than in Column 4 !

In short, the relevant part of the code flow is:

Total_Cnt = Master_FI.Count

Loc_Row = Ceil(Total_Cnt / 4)

For i = 1 to Total_Cnt

// Do some stuff

// Build the “<table…” block:
// Add a “<a href=” line into a Variable for later use

// Determine if I add a New Column or stay in the current one
If Loc_Row = Row_Cnt Then // See (*) below
// Add a brand new Row
// Reset Loc_Row to 0
Else
// Increment the Loc_Row (# of Rows in each Column)
Loc_Row = Loc_Row + 1
End If

// Do some more stuff
Next

// Locate where to place the “<table…” data
// Insert the “<table…” string in the TextArea

Can you tell me what’s wrong in the code design ?

There is a button to save the TextArea Contents nto an html file.
There is another button to render the html from TextArea into an HTMLViewer.

i would collect the data in classes/objects/lists first,
then each object can output itself as part of the whole html.

I do not know how to do that.

The final tests show 50% of incorrect behavior (I may say bugs); when:
Ceil(Item_Nbr / 4) result is .5 or .75: bug
Ceil(Item_Nbr / 4) result is .0 or .25: OK

I suppose that the errors are inverted if when I use Floor (I know the error exits when using Floor: this is why I used Ceil !).

Not very elegant, but I found a solution: I cheated.

wrote the previous message, then had a breakfast and I got an idea:
If have troubles because of the decimal part of a number, remove it !

Then I used:

Row_Cnt = Total_Cnt \ 4

No: I still have problems.

And then I had the idea to cheat.:

Row_Cnt = (Total_Cnt \ 4) + 1 // + 1 makes the difference

Works. Of course, the last column will always have 4 or more rows less than the others, but it will never have one too many (there will never ever will be an unwanted “5th column” ! *)

  • Did you get the second meaning ?

i think i understand what are you doing.
because the limit of 4 columns the height varied.
and if there was one column used and the 3 other not (horizontal) one row was used or is needed.