this method is quite slow on my computer but it gives you the idea of how it could be done. (if this is what you mean)
sync on : sync rate 0
sw = Screen Width()
sh = Screen Height()
Do : CLS 0
Ink RGB( 255, 255, 255 ), 0
GridID = 0
For x = 1 To SW Step 30
For y = 1 To SH Step 30
Inc GridID, 1
Line x, y, x+30, y : ` - : top
Line x+30, y, x+30, y+30 : ` | : right
Line x, y, x, y+30 : `| : left
Line x, y+30, x+30, y+30 : ` - : bottom
If MouseX() >= x And MouseX() <= x+30
If MouseY() >= y And MouseY() <= y+30
InsideGrid = GridID
EndIf
EndIf
Next y
Next x
Ink RGB( 255, 000, 000 ), 0
Text 100, 100, str$( InsideGrid )
Sync : Loop
edit,
if you remove "Line x, y, x, y+30 : `| : left" and "Line x, y, x+30, y : ` - : top" it gets a bit faster.