SortedList question

  • Thread starter Thread starter J L
  • Start date Start date
J

J L

I have a sortedlist (ConflictList) that contains a string identifier
(ShipmentNumber) for the key and a structure (AppointmentInfo) for the
value. The structure memebers are strings, dates and intgers (i.e. no
objects).

I pass this sorted list by reference to a function. And do the
following type of loop

dim i as integer
for i = 0 to ConflictList.count - 1
dim apt as AppointmentInfo = _
Ctype(ConflictList.GetByIndex(i), AppointmentInfo)

< Here is my questions:
After some processing I want to change the value of one of the
memebers of the original sorted list...can I do it by simply assigning
the new value to the variable I declared above?>

apt.Door = theNewDoor

<at this point is the original sorted list changed?>

next

I hope my question makes sense. I get totally confused with the
reference/value/scope issues. Like a mind twister for me :>)

TIA
John
 
Hi,

Instead of using a structure use a class. You will be able to
change values in the sorted list if they contain a class. You will not be
able to change the value in a structure.

Public Class Info
Public name As String
Public AppointmentDate As DateTime
Public Priority As Integer
End Class




Dim slClass As SortedList


slClass = New SortedList
Dim clsAi As New Info
With clsAi
.name = "Ken"
.Priority = 1
.AppointmentDate = Now
End With

slClass.Add(1, clsAi)

DirectCast(slClass.Item(1), Info).name = "New Name"

Trace.WriteLine(DirectCast(slClass.Item(1), Info).name)


Ken
-----------------
I have a sortedlist (ConflictList) that contains a string identifier
(ShipmentNumber) for the key and a structure (AppointmentInfo) for the
value. The structure memebers are strings, dates and intgers (i.e. no
objects).

I pass this sorted list by reference to a function. And do the
following type of loop

dim i as integer
for i = 0 to ConflictList.count - 1
dim apt as AppointmentInfo = _
Ctype(ConflictList.GetByIndex(i), AppointmentInfo)

< Here is my questions:
After some processing I want to change the value of one of the
memebers of the original sorted list...can I do it by simply assigning
the new value to the variable I declared above?>

apt.Door = theNewDoor

<at this point is the original sorted list changed?>

next

I hope my question makes sense. I get totally confused with the
reference/value/scope issues. Like a mind twister for me :>)

TIA
John
 
Thanks Ken,
I am trying that now. Can I create a variable that references the
original class to keep from having so many DirectCast statements in my
code?

i.e.

dim apt as Info = DirectCast(slClass.Item(1), Info)

and now use apt.name = "New Name"
etc. and have this updating the original class?

Thanks again,
John
 
Hi,

I would use a with statement.

With DirectCast(slClass.Item(1), Info)
.name = "Ken"
.Priority = 1
.AppointmentDate = Now
End With

Ken
-----------------------

Thanks Ken,
I am trying that now. Can I create a variable that references the
original class to keep from having so many DirectCast statements in my
code?

i.e.

dim apt as Info = DirectCast(slClass.Item(1), Info)

and now use apt.name = "New Name"
etc. and have this updating the original class?

Thanks again,
John
 
Great Ken. Thank you for all your help!!

John

Hi,

I would use a with statement.

With DirectCast(slClass.Item(1), Info)
.name = "Ken"
.Priority = 1
.AppointmentDate = Now
End With

Ken
-----------------------

Thanks Ken,
I am trying that now. Can I create a variable that references the
original class to keep from having so many DirectCast statements in my
code?

i.e.

dim apt as Info = DirectCast(slClass.Item(1), Info)

and now use apt.name = "New Name"
etc. and have this updating the original class?

Thanks again,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top