I have a grid whose (x,y) co-ordinates correspond to a SQL Server. There is not a row for every co-ordinate; only the ones that are not blank. There is a column ("fill") that stores these colour code integers.
When the application loads I have a sequence below that loops through every (X,Y) co-ordinate within the height/width of the grid. Within this loop, it asks whether the (X,Y) in question match those in the row and, if this returns TRUE, updates the Fill integer from that saved in the row. If this returns FALSE, I increase the row by one and look again, and again, until it has looked through every row saved in the table (named SQL.RecordCount
). Once this has been done, I increase X (moving right, to the next cell) and do this process again; once I get to the end of the row (where X = MapWidth) I go to the start of the next row and go again. This repeats until Y = MapHeight, as shown in the code below.
To me this sequence makes sense, so there must be something I do not know is missing. Even if you do not have the exact solution, anything to move forward this gridlock would be very much appreciated.
Edits based on comments are in double asterix:
Public Sub LoadMap()
Dim Fill As Integer = 0
Dim Row As Integer = 0
Dim X As Integer = 0
Dim Y As Integer = 0
SQL.ExecQuery("SELECT * FROM Mapper_Table")
Do While Y <= MapHeight
'Ultimate exit statement: stop loading cells when Y becomes greater than the MapHeight...
Do While X <= MapWidth
'Row Exit Statement: When X reaches 100, its time to start on the next row...
Do While Row < SQL.RecordCount '12
'I only want to search as many rows as there are saved locations, otherwise the cell must be empty and therefore blank...
If X = SQL.DBDT.Rows(Row).Item("X") And Y = SQL.DBDT.Rows(Row).Item("Y") Then
'If the current (X,Y) is a match to the database row, then we take the stored colour...
Fill = SQL.DBDT.Rows(Row).Item("Fill")
End If
'If Fill is taken, we can colour the square; otherwise, we should look in the next row...
If Fill <> 0 Then
Map(X, Y, 0) = Fill
End If
** Row = Row + 1 **
Loop
'Once we have looked in all the rows for out cell, it is either coloured in or not; we can move onto the next cell in the row; a.k.a...
X = X + 1
** Fill = 0 **
Loop
'Once we have looked for all the cells in our row, we can move onto the next one; a.k.a...
X = 0
Y = Y + 1
Loop
'Once we get to the end of the map, it should be loaded!
End Sub