Y
YYZ
Short version: I've got to a collection of objects based on a certain
property of those objects. Here is the code to know IF I need to swap
2 elements...
if cdbl(cCol(i).Balance) < cdbl(ccol(i + 1).Balance) then
SwapColItems(i, i+1, cCol)
The SwapColItems Sub looks like this (pared down)
Public Sub SwapColItems(ByVal i1 As Integer, ByVal i2 As Integer,
ByRef cCol As clsLiabilitiesCol)
Dim sTemp As String
sTemp = cCol(i1).Balance
cCol(i1).Balance = cCol(i2).Balance
cCol(i2).Balance = sTemp
End Sub
When I run this, and step through, I see the values being swapped. I
am using the Command Window to verify the collection(1).Balance =
"3000" and collection(2).Balance = "5000", then I step into the swap
routine, and at the end I see that cCol(i1).Balance = "5000" and
cCol(i2).Balance = "3000", which is good.
Then, right after it exits out of this sub, those values have been
reversed again!?!?! I know I'm doing something stupid, but I can't for
the life of my think of what it is!
Can anyone spot what I'm doing wrong? I know I'm forgetting something
stupid, but I've checked the obvious things I can think of (byval vs.
byref, which shouldn't matter in this case because the only values that
need to be preserved are in the cCol class variable, and as I
understand things it doesn't matter if you pass it byval or byref since
it points to an object pointer on the stack, and the data on the heap,
or whatever -- stacks and heaps make my ass twitch).
Any and all help is appreciated.
Matt
property of those objects. Here is the code to know IF I need to swap
2 elements...
if cdbl(cCol(i).Balance) < cdbl(ccol(i + 1).Balance) then
SwapColItems(i, i+1, cCol)
The SwapColItems Sub looks like this (pared down)
Public Sub SwapColItems(ByVal i1 As Integer, ByVal i2 As Integer,
ByRef cCol As clsLiabilitiesCol)
Dim sTemp As String
sTemp = cCol(i1).Balance
cCol(i1).Balance = cCol(i2).Balance
cCol(i2).Balance = sTemp
End Sub
When I run this, and step through, I see the values being swapped. I
am using the Command Window to verify the collection(1).Balance =
"3000" and collection(2).Balance = "5000", then I step into the swap
routine, and at the end I see that cCol(i1).Balance = "5000" and
cCol(i2).Balance = "3000", which is good.
Then, right after it exits out of this sub, those values have been
reversed again!?!?! I know I'm doing something stupid, but I can't for
the life of my think of what it is!
Can anyone spot what I'm doing wrong? I know I'm forgetting something
stupid, but I've checked the obvious things I can think of (byval vs.
byref, which shouldn't matter in this case because the only values that
need to be preserved are in the cCol class variable, and as I
understand things it doesn't matter if you pass it byval or byref since
it points to an object pointer on the stack, and the data on the heap,
or whatever -- stacks and heaps make my ass twitch).
Any and all help is appreciated.
Matt