so it's ugly, but it work, so here it is
squareExp2 can be 9 or 16
Square can be 3 or 4
length of the gridbox and gridbox1 array can be 0 to 80 or 0 to 255
(you see the pattern now)
this code is ran only one time, at runtime
For j = 0 To squareExp2 - 1
For i = 0 To squareExp2 - 1
box = (j * squareExp2) + i
gridbox(box) = ((j \ Square) * squareExp2 * Square) + ((j Mod Square) * Square) + (i \ Square) * squareExp2 + (i Mod Square)
gridbox1(gridbox(box)) = ((j \ Square) * squareExp2 * Square) + (((j Mod Square) * Square) * Square)
Next
Next
goal of the code above is to move the code from
k = (gridRow(pos) \ iSquare) * iSquare
l = (gridCol(pos) \ iSquare) * iSquare
For i = l To l + iSquare - 1
For j = k To k + iSquare - 1
box = (j * squareExp2) + i
foundNumber(grid(box)) = grid(box)
Next
Next
to
j = myGridbox1(i)
For x = j To j + squareExp2 - 1
foundNumber(grid(myGridbox(x))) = grid(myGridbox(x))
Next
* edit *
in the end
Dim Square2 As Integer = iSquare * iSquare
Dim Square3 As Integer = Square2 * iSquare
Dim Square4 As Integer = Square2 * Square2
Dim j2_offset As Integer = 0
For j2 As Integer = 0 To iSquare - 1
Dim j1_offset As Integer = 0
Dim j1_interleaved_offset As Integer = 0
For j1 As Integer = 0 To iSquare - 1
Dim i2_offset As Integer = 0
Dim i2_interleaved_offset As Integer = 0
Dim j_offset_value As Integer = j2_offset + j1_offset
For i2 As Integer = 0 To iSquare - 1
Dim offset_value As Integer = j_offset_value + i2_offset
Dim interleaved_value As Integer = j2_offset + i2_interleaved_offset + j1_interleaved_offset
For i1 As Integer = 0 To iSquare - 1
box = offset_value + i1
gridbox(box) = interleaved_value + i1
gridbox1(gridbox(box)) = j_offset_value
Next
i2_offset += iSquare
i2_interleaved_offset += Square2
Next
j1_offset += Square2
j1_interleaved_offset += iSquare
Next
j2_offset += Square3
Next
Update little followup, a few months later.
It was for a sudoku program and you can find where it being used here