• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Alphabetize in VB?

L

Liger ZERO

Guest
#1
Is there a built in function in Visual Basic that will alphabetize an array of variables?
 
#2
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.
 
#4
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.
 
B

Blitzkrieg

Guest
#5
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 posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,247
Members
89,019
Latest member
fontjohnson