Order addresses so 2,3,4... is before 10 etc

wackywoo105

Registered User.
Local time
Today, 12:50
Joined
Mar 14, 2014
Messages
203
I use the following code to reorganize an address list:

Code:
   pvarArray() = Split(addlist, "^")
    
    Dim p As Long
    Dim iMin As Long
    Dim iMax As Long
    Dim varSwap As Variant
    Dim blnSwapped As Boolean
    
    iMin = LBound(pvarArray)
    iMax = UBound(pvarArray) - 1
    Do
        blnSwapped = False
        For p = iMin To iMax
            If pvarArray(p) > pvarArray(p + 1) Then
                varSwap = pvarArray(p)
                pvarArray(p) = pvarArray(p + 1)
                pvarArray(p + 1) = varSwap
                blnSwapped = True
            End If
        Next
        iMax = iMax - 1
    Loop Until Not blnSwapped
    
   For t = LBound(pvarArray) To UBound(pvarArray)
       ' MsgBox pvarArray(t)
        Me.List2.AddItem pvarArray(t)
   Next t


The problem is that address such as number 2 are placed after 18 and so on.

Can anyone provide a way to list them so 1,2,3 etc are all at the start of the list?
 
use clng(arrayval) to compare the numeric values

ok, as long as all the values ARE numeric.
Addresses like 34A will fail.

you could try val(arrayval), but this isn't foolproof either.

The problem is you are comparing strings, not numbers, and 10 sorts before 2, in a dictionary sort.
 
Val() certainly looks interesting. I will have to have a play.
 
val returns the numeric left part of a string as a number, but some non-numbers can be treated as numbers in some cases,

eg
? val("&H4B") treats 4B as Hex, and returns 75.

You should be OK with normal house numbers, I think.
 

Users who are viewing this thread

Back
Top Bottom