Alphabetize in VB?

L

Liger ZERO

Guest
Is there a built in function in Visual Basic that will alphabetize an array of variables?
 
This seems to be a bit of a misnomer to me. Arrays are treated as a single variable in VB; the only difference is that it’s indexed internally. If you wish to input the entire alphabet into an array in the correct order so as to produce the expected result of a =1 b=2 (or the reverse) you would have to sort all the letters prior to pushing them into the array. This is kind of like doing the same equation twice and is best avoided, however this does have its place where huge amounts of comparisons need to be done quickly with little output translation or to push straight into another function. This is a complex subject and one reason why I mostly design my own arrays that can accept any data type as apposed to visual basics single data type.
 
Arrays: -

These should have made illegal years ago. Whilst there may be the occasional use that might have been justified ten years ago I can’t see any use for them in a modern computer language as is you have to “strap-up” one set of variables and then compare the with another, your programme is badly designed or even not thought through.

Arrays: -

Don’t use them. END.
 
Unfortunately everyone here is right, there isn't a built in function to sort alphabetically in Visual Basic. However, a sub routine can easily be built to do it. There are a few different ways of doing it, one of the most popular is known as a 'Bubble Sort'

Sub sorter(theArray)
Dim indexLimit As Long, lastSwap As Long
Dim firstItem As Long
Dim index As Long
Dim value As Variant

Do
indexLimit = UBound(theArray) - 1
lastSwap = 0

For index = firstItem To indexLimit
value = theArray(index)
If (value > theArray(index + 1)) Then
theArray(index) = theArray(index + 1)
theArray(index + 1) = value
lastSwap = index
End If
Next
Loop While lastSwap

For i = 0 To UBound(theArray) - 1
testing(i) = theArray(i)
Next i
End Sub

Just use this code (I made it in a couple minutes so its not perfect)

At the bottom where it says 'testing(i)' just change the 'testing' to the name of the array you are sorting.

Then an example of its use would be:

sorter(theArrayYouAreSorting)

Hope this helps. :D
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back