Solved

VBA bubble sort compile error.

Posted on 2013-11-25
4
252 Views
Last Modified: 2013-11-25
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

Do
  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.
0
Comment
Question by:tesla764
  • 2
4 Comments
 
LVL 7

Expert Comment

by:SterlingMcClung
ID: 39675129
You are missing something between:

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

Author Comment

by:tesla764
ID: 39675152
I'm not sure what would go there.
0
 

Author Comment

by:tesla764
ID: 39675206
Could you tell if this Bubble sort would even work?
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 500 total points
ID: 39675414
Just answered your duplicate question...
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now