Avatar of tesla764
tesla764 asked on

VBA bubble sort compile error.

I receive the following error...

Compile error:
Expected: )

The statement below turns red...
If (ToSort(BubbleSort) ToSort(BubbleSort + 1) And SortAscending) _
          Or (ToSort(BubbleSort) < ToSort(BubbleSort + 1) And Not SortAscending) Then

I am just not seeing what the compiler is referring to. Could someone please help.

The Code...
Sub BubbleSort(ToSort As Variant, Optional SortAscending As Boolean = True)

Dim AnyChanges As Boolean
Dim BubbleSort As Long
Dim SwapFH As Variant

  AnyChanges = False
    For BubbleSort = LBound(ToSort) To UBound(ToSort) - 1
      If (ToSort(BubbleSort) ToSort(BubbleSort + 1) And SortAscending) _
          Or (ToSort(BubbleSort) < ToSort(BubbleSort + 1) And Not SortAscending) Then
          ' These two need to be swapped
          SwapFH = ToSort(BubbleSort)
          ToSort(BubbleSort) = ToSort(BubbleSort + 1)
          ToSort(BubbleSort + 1) = SwapFH
          AnyChanges = True
      End If
    Next BubbleSort
Loop Until Not AnyChanges

End Sub

Thanks in advance.
Microsoft Development.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

You are missing something between:

ToSort(BubbleSort) <<somthing here>> ToSort(BubbleSort + 1)

I'm not sure what would go there.

Could you tell if this Bubble sort would even work?
Your help has saved me hundreds of hours of internet surfing.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question