A
AGP
VB2005
Having trouble populating a structure that has a List(Of) component. The
concept is a trip consists of several roads and each road consists of
several segments. here is my declaration and a typical assignment and the
place where i get an exception:
Public Structure tRoadSeg
Dim startpt As String
Dim endpt As String
Dim markers As Integer
Dim itype As Integer
End Structure
Public Structure tRoad
Dim name As String
Dim id As Integer
Dim parts As Integer
Dim RoadSegs As List(Of tRoadSeg)
End Structure
Public Structure tTrip
Dim stdate As DateTime
Dim sFrom As String
Dim sTo As String
Dim wx As String
Dim vehid As Integer
Dim driver As String
Dim Roads As List(Of tRoad)
End Structure
'a collection of trips
Dim zTrips As List(Of tTrip) = New List(Of tTrip)
'a single trip
Dim zTrip As tTrip = Nothing
'a single road
Dim zRoad As tRoad = Nothing
'add one trip to the trip collection
zTrip.driver = "Me"
zTrip.sFrom = "Phoenix"
zTrip.sTo = "Seattle"
zTrip.vehid = 0
zTrips.Add(zTrip)
'create a road
zRoad.id = 300
zRoad.parts = 5
'all road segments start with the city where we start the trip so we create
a road segment
Dim roadSegAtStart As tRoadSeg = New tRoadSeg
roadSegAtStart.endpt = zTrip.sFrom
'and add that as the first road segment element in our road. we will add
more segments later
zRoad.RoadSegs.Add(roadSegAtStart) <----- ***** Exception here *****
'and add our road to our trip
zTrip.Roads.Add(zRoad) <----- ***** Exception here *****
The exception is of type System.NullReferenceException: Object reference not
set to an instabce of an object. I just cant figure out why Im getting this
exception. Im almost certain im not initializing something properly but cant
put my finger on it. Any help is appreciated.
AGP
Having trouble populating a structure that has a List(Of) component. The
concept is a trip consists of several roads and each road consists of
several segments. here is my declaration and a typical assignment and the
place where i get an exception:
Public Structure tRoadSeg
Dim startpt As String
Dim endpt As String
Dim markers As Integer
Dim itype As Integer
End Structure
Public Structure tRoad
Dim name As String
Dim id As Integer
Dim parts As Integer
Dim RoadSegs As List(Of tRoadSeg)
End Structure
Public Structure tTrip
Dim stdate As DateTime
Dim sFrom As String
Dim sTo As String
Dim wx As String
Dim vehid As Integer
Dim driver As String
Dim Roads As List(Of tRoad)
End Structure
'a collection of trips
Dim zTrips As List(Of tTrip) = New List(Of tTrip)
'a single trip
Dim zTrip As tTrip = Nothing
'a single road
Dim zRoad As tRoad = Nothing
'add one trip to the trip collection
zTrip.driver = "Me"
zTrip.sFrom = "Phoenix"
zTrip.sTo = "Seattle"
zTrip.vehid = 0
zTrips.Add(zTrip)
'create a road
zRoad.id = 300
zRoad.parts = 5
'all road segments start with the city where we start the trip so we create
a road segment
Dim roadSegAtStart As tRoadSeg = New tRoadSeg
roadSegAtStart.endpt = zTrip.sFrom
'and add that as the first road segment element in our road. we will add
more segments later
zRoad.RoadSegs.Add(roadSegAtStart) <----- ***** Exception here *****
'and add our road to our trip
zTrip.Roads.Add(zRoad) <----- ***** Exception here *****
The exception is of type System.NullReferenceException: Object reference not
set to an instabce of an object. I just cant figure out why Im getting this
exception. Im almost certain im not initializing something properly but cant
put my finger on it. Any help is appreciated.
AGP