Hi I'm having a strange problem with creating a list of 'types', hope someone can spot what I'm missing!
First off the working code. Simply stores a load of strings from a database into a list, I've missed out some of the non essential stuff like the cursor object initliasing etc :-
Dim streets As List
streets.Initialize
c=SQL.ExecQuery("SELECT * from lut_street ORDER BY name")
For i = 0 To c.RowCount - 1
c.Position=i
streets.Add(c.GetString("name"))
Next
this works as expected - streets is an array of streetnames.
But I want to make it slightly better by having a 'streets' type, which stores the lat and long which I retrieve from the database. So the same code as above except :-
Type StreetInfo(id As String, name As String,lon As String, lat As String)
Dim thisStreet As StreetInfo
For i = 0 To c.RowCount - 1
thisStreet.Initialize
c.Position=i
thisStreet.id=c.GetString("id")
thisStreet.name=c.GetString("name")
thisStreet.lat=c.GetString("geo_lat")
thisStreet.lon=c.GetString("geo_long")
Log("this Streets is currently "&thisStreet)
streets.Add(thisStreet)
Next
I would expect this to create a list of 'streetinfo' objects but it doesn't - it creates the correct number of entries/rows, but each one holds the same information - the last row retrieved from the database.
Hopefully someone will be able to point out my silly mistake? many thanks!
First off the working code. Simply stores a load of strings from a database into a list, I've missed out some of the non essential stuff like the cursor object initliasing etc :-
Dim streets As List
streets.Initialize
c=SQL.ExecQuery("SELECT * from lut_street ORDER BY name")
For i = 0 To c.RowCount - 1
c.Position=i
streets.Add(c.GetString("name"))
Next
this works as expected - streets is an array of streetnames.
But I want to make it slightly better by having a 'streets' type, which stores the lat and long which I retrieve from the database. So the same code as above except :-
Type StreetInfo(id As String, name As String,lon As String, lat As String)
Dim thisStreet As StreetInfo
For i = 0 To c.RowCount - 1
thisStreet.Initialize
c.Position=i
thisStreet.id=c.GetString("id")
thisStreet.name=c.GetString("name")
thisStreet.lat=c.GetString("geo_lat")
thisStreet.lon=c.GetString("geo_long")
Log("this Streets is currently "&thisStreet)
streets.Add(thisStreet)
Next
I would expect this to create a list of 'streetinfo' objects but it doesn't - it creates the correct number of entries/rows, but each one holds the same information - the last row retrieved from the database.
Hopefully someone will be able to point out my silly mistake? many thanks!