Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Alphabetically list an Array
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Oct 8th, 2003 04:07 AM    Post subject: Alphabetically list an Array Reply with quote

Code:
Public Function SortArray(Expression()) As Variant()
Dim Temp As Variant, SortArrayNew() As Variant
SortArrayNew = Expression
For Index = 1 To UBound(Expression)
  For Counter = 1 To UBound(Expression) - 1
   If SortArrayNew(Counter) > SortArrayNew(Counter + 1) Then 'sort by weight
    Temp = SortArrayNew(Counter)
    SortArrayNew(Counter) = SortArrayNew(Counter + 1) 'I think this works
    SortArrayNew(Counter) = SortArrayNew(Counter + 1)
    SortArrayNew(Counter + 1) = Temp
   End If
  Next Counter
Next Index
SortArray = SortArrayNew
End Function


Usage with Example:
Code:
Private Sub Form_Load()
Dim x()
ReDim x(1 To 3)
x(1) = "b"
x(2) = "a"
x(3) = "c"
x = SortArray(x)
For i = 1 To 3
  MsgBox x(i)
Next
End Sub
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic