G
Glenn Grant via .NET 247
I am trying to create an Array of type Hash Table. When I try to assign a value to a key in the hash table i get a System.NullReferenceException error.
Here is the code:
Public Function ReadTilesFromFile(ByVal Path As String, Optional ByVal TilesetDir As String = "tilesets/")
Dim i As Integer ' Counter for loops
Dim TilesetPath As String = TilesetDir & Path ' Full path to tileset file
Dim xDS As New Tileset() ' Make xDS point to Tilset
Dim xRow As Tileset.TilesRow ' Make xRow point to Tileset.TilesRow
If New FileInfo(TilesetPath).Exists Then ' If the tileset file exists
xDS.ReadXml(TilesetPath, _
System.Data.XmlReadMode.IgnoreSchema) ' Read tiles table from file
If xDS.Tiles.Rows.Count > 0 Then ' Check if there are rows in the table
For i = 0 To (xDS.Tiles.Rows.Count - 1) ' For each row in the table
xRow = xDS.Tiles.Rows.Item(i) ' Use the current row of the table
ReDim Preserve aryTiles(i)
MsgBox("die")
MsgBox(aryTiles(i).Count)
' AsciiTile
If Not xRow.IsAsciiTileNull() Then ' If there is data in the AsciiTile field
'aryTiles(i).Add("AsciiTile", xRow.AsciiTile) ' Put the data in the Tiles hashtable
aryTiles(i).Item("AsciiTile") = xRow.AsciiTile
End If
MsgBox("die1")
' Image
If Not xRow.IsImageNull() Then ' If there is data in the Image field
aryTiles(i).Add("Image", xRow.Image) ' Put the data in the Tiles hashtable
End If
Next i
End If
Else
TilesetError(1) ' Call TilesetError, MissingTilesetFile
End If
End Function
Here is the code:
Public Function ReadTilesFromFile(ByVal Path As String, Optional ByVal TilesetDir As String = "tilesets/")
Dim i As Integer ' Counter for loops
Dim TilesetPath As String = TilesetDir & Path ' Full path to tileset file
Dim xDS As New Tileset() ' Make xDS point to Tilset
Dim xRow As Tileset.TilesRow ' Make xRow point to Tileset.TilesRow
If New FileInfo(TilesetPath).Exists Then ' If the tileset file exists
xDS.ReadXml(TilesetPath, _
System.Data.XmlReadMode.IgnoreSchema) ' Read tiles table from file
If xDS.Tiles.Rows.Count > 0 Then ' Check if there are rows in the table
For i = 0 To (xDS.Tiles.Rows.Count - 1) ' For each row in the table
xRow = xDS.Tiles.Rows.Item(i) ' Use the current row of the table
ReDim Preserve aryTiles(i)
MsgBox("die")
MsgBox(aryTiles(i).Count)
' AsciiTile
If Not xRow.IsAsciiTileNull() Then ' If there is data in the AsciiTile field
'aryTiles(i).Add("AsciiTile", xRow.AsciiTile) ' Put the data in the Tiles hashtable
aryTiles(i).Item("AsciiTile") = xRow.AsciiTile
End If
MsgBox("die1")
' Image
If Not xRow.IsImageNull() Then ' If there is data in the Image field
aryTiles(i).Add("Image", xRow.Image) ' Put the data in the Tiles hashtable
End If
Next i
End If
Else
TilesetError(1) ' Call TilesetError, MissingTilesetFile
End If
End Function