In the "Search Box" above type in "Make a Grid in Small Basic" you will see several examples. One of those was made by LitDev who is very good at programming. Below is his example. I would suggest that you look up his post as it gives
a good discussion on how the grid works.
For r = 1 To rows
For c = 1 To columns
GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
boxes[r][c] = Shapes.AddRectangle(size, size)
Shapes.Move(boxes[r][c], offsetX + (c-1)*size, offsetY + (r-1)*size )