View Full Version : i have a problem with my user defined class

02-25-2009, 10:28 AM
i am sure the answer to this is silly, but here goes. i have the following code. it includes a class called transforms, with members and come a function to test the class. the problem is that i have a class method called ReverseLastTransform() which is supposed to reverse the +/- of the values in each of the vector array values, bit this is not working. i am sure i am doing overlooking something really obvious. any help will be appreciated
Public VectorStack As New Collection
Public Sub AddVector(item As Variant)
'perform validation before adding to ensure 0 to 3) double vector array
VectorStack.add (item)
End Sub
Public Sub DeleteVector(index As Integer)
VectorStack.Remove (index)
End Sub
Public Sub ReverseLastTransform()
Dim count As Integer
count = VectorStack.count
Dim VectorElement As Variant
For Each VectorElement In Me.VectorStack.item(count)
VectorElement = VectorElement * -1
Next VectorElement
End Sub
Public Sub ReverseAllTransforms()
'placeholder for class method
MsgBox "we are in ReverseAllTransforms"
End Sub
'TEST CODE------------------------------------
Public Function TestTransform()
Dim MyTransformStack As New transform
Dim vector_1(0 To 3), vector_2(0 To 3), vector_3(0 To 3) As Variant
vector_1(0) = 5#: vector_1(1) = 5#: vector_1(2) = 5#: vector_1(3) = 91#
vector_2(0) = 6#: vector_2(1) = 6#: vector_2(2) = 6#: vector_2(3) = 92#
vector_3(0) = 7#: vector_3(1) = 7#: vector_3(2) = 7#: vector_3(3) = 93#

MyTransformStack.AddVector vector_1
MyTransformStack.AddVector vector_2
MyTransformStack.AddVector vector_3
End Function

02-25-2009, 10:53 AM
Public Sub ReverseLastTransform()
Dim VectorElement As Variant
Dim i As Long, j As Long

VectorElement = VectorStack.item(VectorStack.count)
For i = LBound(VectorElement) To UBound(VectorElement)

VectorElement(i) = -VectorElement(i)
Next i
DeleteVector VectorStack.count
AddVector VectorElement
End Sub

02-25-2009, 11:07 AM
the values are changed within the scope of the class method but not out into the test routine. how do i do this? also, why did you change from fer each to a for loop uisng upper and lower bounds? is it just a preference or is ther a problem with using the 'for each'. thanks again for your response.

02-25-2009, 12:51 PM
You need to read the values from the class in the test procedure.