A
Alan Beban
The following procedure works correctly to load arr2 with red, blue,
Blue, brown if CaseSensitive is True; and to load it with red, blue,
brown if CaseSensitive is False. When I attempt to declare the variable
x like so (which is commented out in the procedure)
If CaseSensitive Dim x As Dictionary Else Dim x As Collection
it throws a compile error--Duplicate declaration in current scope.
How can the variable x be appropriately declared?
Sub abc()
'This procedure requires project reference to
'the "Microsoft Scripting Runtime"
Dim arr, arr2, i As Long
'If CaseSensitive Dim x As Dictionary Else Dim x As Collection
CaseSensitive = True
'CaseSensitive = False
arr = Array("red", "blue", "Blue", "red", "brown")
If CaseSensitive Then Set x = New Dictionary Else Set x = New Collection
On Error Resume Next
For Each Elem In arr
x.Add Item:=Elem, key:=CStr(Elem)
Next
On Error GoTo 0
ReDim arr2(1 To x.Count)
i = 1
For Each Elem In x
arr2(i) = Elem
i = i + 1
Next
End Sub
Thanks,
Alan Beban
Blue, brown if CaseSensitive is True; and to load it with red, blue,
brown if CaseSensitive is False. When I attempt to declare the variable
x like so (which is commented out in the procedure)
If CaseSensitive Dim x As Dictionary Else Dim x As Collection
it throws a compile error--Duplicate declaration in current scope.
How can the variable x be appropriately declared?
Sub abc()
'This procedure requires project reference to
'the "Microsoft Scripting Runtime"
Dim arr, arr2, i As Long
'If CaseSensitive Dim x As Dictionary Else Dim x As Collection
CaseSensitive = True
'CaseSensitive = False
arr = Array("red", "blue", "Blue", "red", "brown")
If CaseSensitive Then Set x = New Dictionary Else Set x = New Collection
On Error Resume Next
For Each Elem In arr
x.Add Item:=Elem, key:=CStr(Elem)
Next
On Error GoTo 0
ReDim arr2(1 To x.Count)
i = 1
For Each Elem In x
arr2(i) = Elem
i = i + 1
Next
End Sub
Thanks,
Alan Beban