Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Grid Formatting Demo
#13
(02-21-2025, 09:58 PM)madscijr Wrote: Is my program's output not correct? 
Anyway, thanks again for your patience and time with this...
I will follow up later!

Actually, in this case, you have found the simplest of goofs in my code. In fact, it's such a simple thing, that it's BLEEPING embarrassing that nobody caught it sooner.

Look at this snippet of the old code:

Code: (Select All)
Sub CalculateGrids (items)
    For i = 1 To UBound(Ratio)
        n = 1
        Do Until Ratio(i).size * n ^ 2 > items
            n = n + 1
        Loop
        Ratio(i).scale = n 'this is the scaler
        Ratio(i).total = Ratio(i).size * n ^ 2 'this is the total number of cells
        Ratio(i).empty = Ratio(i).total - items
    Next
End Sub

Let's zoom in one one line in specific:

Do Until Ratio(i).size * n ^ 2 > items

What's that line basically say for us to do?

Expand the grid until it has more spaces than our desired number of items.

Let's reiterate and stress the main point: *more spaces*

NOTE that we don't really need MORE spaces. We need at least THE NUMBER of spaces, or MORE....

Change that single line to the following excessive alteration:

Do Until Ratio(i).size * n ^ 2 >= items

Now you'll get back 0 spaces left over for perfect fit solutions.

7500 items, in a 4:3 ratio results in a 25x scaler for 100x75 grid layout with 0 spaces left over.

You don't need MORE spaces; just ENOUGH spaces and by skipping that equal sign there, we missed this very common use case. Code has been edited and fixed in the original post (that was haaard work editing that, LOL!), and you shouldn't see this glitch any longer.
Reply


Messages In This Thread
Grid Formatting Demo - by SMcNeill - 02-21-2025, 05:59 PM
RE: Grid Formatting Demo - by Pete - 02-21-2025, 06:52 PM
RE: Grid Formatting Demo - by SMcNeill - 02-21-2025, 06:54 PM
RE: Grid Formatting Demo - by madscijr - 02-21-2025, 07:09 PM
RE: Grid Formatting Demo - by SMcNeill - 02-21-2025, 07:29 PM
RE: Grid Formatting Demo - by madscijr - 02-21-2025, 07:45 PM
RE: Grid Formatting Demo - by Pete - 02-21-2025, 07:13 PM
RE: Grid Formatting Demo - by SMcNeill - 02-21-2025, 07:36 PM
RE: Grid Formatting Demo - by SMcNeill - 02-21-2025, 08:07 PM
RE: Grid Formatting Demo - by Pete - 02-21-2025, 08:15 PM
RE: Grid Formatting Demo - by madscijr - 02-21-2025, 09:26 PM
RE: Grid Formatting Demo - by madscijr - 02-21-2025, 09:58 PM
RE: Grid Formatting Demo - by SMcNeill - Yesterday, 12:16 AM
RE: Grid Formatting Demo - by madscijr - Yesterday, 03:49 AM



Users browsing this thread: 1 Guest(s)