Solved

VBA bubble sort compile error.

Posted on 2013-11-25
4
260 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

8 Experts available now in Live!

Get 1:1 Help Now