M
mosscliffe
I thought I was getting the hang of all this VB and OOP etc, so I
thought I would test ArrayList and Session Variables.
I defined a Class of three variables and added values to them.
I looped 5 times and added the class to an arraylist
I added the arraylist to a session variable and then read it back into
a new array
It said there were 5 entries and the 'foreach' loops five times, but it
always gives me the values of the last class object added
Is there some indexing I have missed ?
Its been a hard day and if I can crack this, it will have been a very
productive one.
Thanks for looking.
DebugPrint is my adding to a Label routine to see what is going on, as
I have not fully got to grips with Watch etc
Public Class clCategory
Public CatID As Integer
Public CatName As String
Public CatDesc As String
End Class
public sub MyCats
'Create ArrayList
Dim fred As New clCategory
Dim arrCats As New ArrayList
Dim x As Integer
For x = 1 To 5
fred.CatID = x
fred.CatName = "CAT" & x.ToString
fred.CatDesc = "Cat Desc:" & x.ToString & x.ToString
arrCats.Add(fred)
'DebugPrint("arrayCats", "Count", arrCats.Count)
Next
Session("SelCats") = arrCats
'Retrieve ArrayList
Dim sessCats As ArrayList
sessCats = Session("SelCats")
DebugPrint("arrayCats", "Count", sessCats.Count)
For Each tim As clCategory In sessCats
DebugPrint("Cat", "CatID", tim.CatID)
DebugPrint("Cat", "CatName", tim.CatName)
DebugPrint("Cat", "CatDesc", tim.CatDesc)
Next
End Sub
thought I would test ArrayList and Session Variables.
I defined a Class of three variables and added values to them.
I looped 5 times and added the class to an arraylist
I added the arraylist to a session variable and then read it back into
a new array
It said there were 5 entries and the 'foreach' loops five times, but it
always gives me the values of the last class object added
Is there some indexing I have missed ?
Its been a hard day and if I can crack this, it will have been a very
productive one.
Thanks for looking.
DebugPrint is my adding to a Label routine to see what is going on, as
I have not fully got to grips with Watch etc
Public Class clCategory
Public CatID As Integer
Public CatName As String
Public CatDesc As String
End Class
public sub MyCats
'Create ArrayList
Dim fred As New clCategory
Dim arrCats As New ArrayList
Dim x As Integer
For x = 1 To 5
fred.CatID = x
fred.CatName = "CAT" & x.ToString
fred.CatDesc = "Cat Desc:" & x.ToString & x.ToString
arrCats.Add(fred)
'DebugPrint("arrayCats", "Count", arrCats.Count)
Next
Session("SelCats") = arrCats
'Retrieve ArrayList
Dim sessCats As ArrayList
sessCats = Session("SelCats")
DebugPrint("arrayCats", "Count", sessCats.Count)
For Each tim As clCategory In sessCats
DebugPrint("Cat", "CatID", tim.CatID)
DebugPrint("Cat", "CatName", tim.CatName)
DebugPrint("Cat", "CatDesc", tim.CatDesc)
Next
End Sub