View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Call sub with array

and this

For X = LBound(TheArray) To UBound(TheArray)

should be

For X = LBound(TheArray) To UBound(TheArray) - 1

as I gave you

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Arne Hegefors" wrote in message
...
Hi Bob! Thanks alot for your answer! I have been spending a whole working
day
on this and I still cannot solve it. I used you code but I cannot get it
to
work. My code looks like this:

SortArray (A)
basel = Á(2)
End Function
.......
Function SortArray(ByRef TheArray As Variant)
Dim Sorted As Boolean
Dim X As Long
Dim B As String
Dim temp
Sorted = False
Do While Not Sorted
Sorted = True
For X = LBound(TheArray) To UBound(TheArray)
If TheArray(X) TheArray(X + 1) Then
temp = TheArray(X + 1)
TheArray(X + 1) = TheArray(X)
TheArray(X) = temp
Sorted = False
End If
Next X
Loop
End Function

the idea is to sort the array A and then present the number that has
position 2. But there is still someting wrong and I have no idea! If
anyone
can help me please do so! Any help appreciated! Thanks alot!

"Bob Phillips" skrev:

Function SortArray(ByRef TheArray As Variant)
Dim Sorted As Boolean
Dim X As Long
Dim temp
Sorted = False
Do While Not Sorted
Sorted = True
For X = LBound(TheArray) To UBound(TheArray) - 1
If TheArray(X) TheArray(X + 1) Then
temp = TheArray(X + 1)
TheArray(X + 1) = TheArray(X)
TheArray(X) = temp
Sorted = False
End If
Next X
Loop
End Function



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Arne Hegefors" wrote in message
...
Hi! I have a problem with an array that I have in a udf. I send the
array
to
another udf in order to sort the array. Somewhere there it goes wrong
and
the
code stops.
..
Call SortArray(A)
basel = A(2)

End Function
...
Function SortArray(ByRef TheArray As Variant)
Sorted = False
Do While Not Sorted
Sorted = True
For X = 1 To UBound(TheArray)
If TheArray(X) TheArray(X + 1) Then
Temp = TheArray(X + 1)
TheArray(X + 1) = TheArray(X)
TheArray(X) = Temp
Sorted = False
End If
Next X
Loop
End Function

The sorting seems to work just fine but the code never goes back to the
line
basel = A(2). Instead it goes back to the line before the Call
SortArray.
I
have no idea what is wrong. Please if anyone can help me! Thanks a lot!