Why do you put the if function inside the field repetition box to return 1 or empty like this? Seems needlessly complex.
Instead of repeatedly evaluating the same complex expression, why not perform a find that limits your found set to only records that meet this criteria?
I can see that Owned_Music_Library::Where_Stored receives a number form $$Box, but don't see where any field gets a "box" or "shelf" label.
And you can simplify your set variable steps by replacing $$Box + 0 with just $$Box (and likewise with $itemcount.)
That leaves me a bit puzzled by how your script is supposed to work here...
Speaking in general terms, if all your records have a field with "shelf" or "box" and a second field with the shelf/box number, you can define two summary fields to report the maximum and minimum of your "coupling number" field.
Then you can set up a summary report with a sub summary part when sorted by ShelfBoxNumb and put these two summary fields, separated by a hyphen inside this sub summary part.
Remove the body layout part from this layout.
Now, if you sort your records by location type (box or shelf) and then also ShelfBoxNumb, you'll get a list of locations with the number ranges found in each location.