You are here:

Visual Basic/string manipulation


Patrick wrote at 2013-01-29 12:39:41
The given code works if ALL values are different. If some values occur more than once, it doesn't work correctly. It should be:

Public Sub QuickSort(vArray As Variant, inLow As Long, inHi As Long)


  Dim pivot   As Variant

  Dim tmpSwap As Variant

  Dim tmpLow  As Long

  Dim tmpHi   As Long


  tmpLow = inLow

  tmpHi = inHi


  pivot = vArray((inLow + inHi) \ 2)


  While (tmpLow <= tmpHi)


    While (vArray(tmpLow) < pivot And tmpLow < inHi)

       tmpLow = tmpLow + 1



    While (pivot < vArray(tmpHi) And tmpHi > inLow)

       tmpHi = tmpHi - 1


    If (tmpLow <= tmpHi) Then

      If (tmpLow < tmpHi) And vArray(tmpLow) <> vArray(tmpHi) Then

        tmpSwap = vArray(tmpLow)

        vArray(tmpLow) = vArray(tmpHi)

        vArray(tmpHi) = tmpSwap

      End If

      tmpLow = tmpLow + 1

      tmpHi = tmpHi - 1

    End If




  If (inLow < tmpHi) Then QuickSort vArray, inLow, tmpHi

  If (tmpLow < inHi) Then QuickSort vArray, tmpLow, inHi


End Sub

This code works well with this input:

5; 7; 5; 2; 8; 4; 6; 2; 3; 5; 1; 8; 5; 7; 3

Visual Basic

All Answers

Answers by Expert:

Ask Experts


Robert Nunemaker


String manipulation, Database access and usage, Class creation, and encapsulation are my strong suits. Active X Controls and DLL`s also. Although I don`t deal with Crystal - frankly because I don`t like it; I prefer to do things manually.


Employment history: Programmed with the Air Force for 15 years, and have continued in the private sector for the past 1 year. Used VB (all versions) for the past 8 years.

Organizations: MCP and MCSD certified.

Education: Computer Science Bachelor degree.

Awards: MCP and MCSD certified.

©2017 All rights reserved.

[an error occurred while processing this directive]