Reputation: 1445
I have the following two arrays:
Sub ArrayLoop(array1, array2)
Dim Students() As Variant
Set myDocument = ActivePresentation.Slides(1)
ENG1 = Array(423.5482, 425.6641, 425.6641)
ENG2 = Array(224.0202, 222.5737, 222.5737)
GER1 = Array(454.692, 454.0753, 454.0753)
GER2 = Array(220.8373, 222.2446, 224.3517)
For i = 0 To 40
x1 = parameter1(i)
x2 = parameter2(i)
y1 = parameter1(i + 1)
y2 = parameter2(i + 1)
With myDocument.Shapes.AddLine(BeginX:=x1, BeginY:=x2, EndX:=y1, EndY:=y2).Line
.DashStyle = msoLineDashDotDot
.ForeColor.RGB = RGB(50, 0, 128)
End With
Next i
End Sub
What I basically want to do now is fire the macro "ArrayLoop" with two parameters and then that array should be used. S0
ArrayLoop(ENG1, ENG2)
Should work with the Array's ENG1 and ENG2
However when I do this
Call ArrayLoop(ENG1, ENG2)
I get an error 13 that says, the items are not comparable. Any thoughts on how I should get this working?
Upvotes: 0
Views: 29
Reputation: 29352
ENG1
and ENG2
need to be passed as paramaters to the sub. In your code, they are defined as local variables. When invoking a routine with parameters, these parameters need to be defined elsewhere and passed to the routine.
Sub ArrayLoop(array1, array2)
Dim i As Long
For i = LBound(array1) To UBound(array1) - 1
With ActivePresentation.Slides(1).Shapes.AddLine(BeginX:=array1(i), BeginY:=array2(i), EndX:=array1(i + 1), EndY:=array2(i + 1)).Line
.DashStyle = msoLineDashDotDot
.ForeColor.RGB = RGB(50, 0, 128)
End With
Next
End Sub
Now here's how you define parameters and call the routine:
Sub TestArrayLoop()
Dim ENG1, ENG2, GER1, GER2
ENG1 = Array(423.5482, 425.6641, 425.6641)
ENG2 = Array(224.0202, 222.5737, 222.5737)
GER1 = Array(454.692, 454.0753, 454.0753)
GER2 = Array(220.8373, 222.2446, 224.3517)
ArrayLoop ENG1, ENG2 ' <----- invoke the routine and pass it the parameters
End Sub
Upvotes: 1