Yesterday, 12:16 AM
(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.