rearrange an array in a different order

  • Thread starter Thread starter clui
  • Start date Start date
C

clui

I have this array myarray(3) with these values:
myarray(1)="Y"
myarray(2)="Other"
myarray(3)="N"

Now I need to have the array in the following order:
myarray(1)="N"
myarray(2)="Y"
myarray(3)="Other"

What's the code for that? Thanks
 
clui said:
I have this array myarray(3) with these values:
myarray(1)="Y"
myarray(2)="Other"
myarray(3)="N"Sub Main()
Dim myArray(1 To 3)
myArray(1) = "Y"
myArray(2) = "Other"
myArray(3) = "N"

SwapTwo myArray(3), myArray(2)
SwapTwo myArray(1), myArray(2)

For i = 1 To 3
Debug.Print "myarray(" & i & ") = " & myArray(i)
Next
End Sub

produces:
myarray(1) = N
myarray(2) = Y
myarray(3) = Other
 
Well that got all jumbled up:

Sub SwapTwo( item1, item2 )
Dim temp as Variant
temp = item1
item1 = item2
item2 = temp

End Sub

Sub Main()
Dim myArray(1 To 3)
myArray(1) = "Y"
myArray(2) = "Other"
myArray(3) = "N"

SwapTwo myArray(3), myArray(2)
SwapTwo myArray(1), myArray(2)

For i = 1 To 3
Debug.Print "myarray(" & i & ") = " & myArray(i)
Next
End Sub
 
Back
Top