Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need a sort
Message
 
À
19/12/1999 09:53:05
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00305859
Message ID:
00305864
Vues:
24
>I'm coming from Foxpro and was rather surprised to find that VB5 didn't have a function to perform a sort. It appears to be something that I'll have to add myself. My first question is, can someone confirm that for me? Maybe I'm just missing it??
>
>If I'm right, however, does someone have a prewritten sort function that I can plug into my app? I'm going to need to sort an arrayname(x, y) array and make sure that the x, y elements that are related as they come in stay related to each other. (Hope that's being clear enough -- need more coffee).

You are absolutely right. VB don't include a Sort Array function.

Here is a small function that you can adapt to your needs:

Type uApplication
strStartupCode As String
strEXEName As String
strDirLastVersion As String
strDirDestination As String
End Type
Private marrApplication() As uApplication

Private Sub SortArray()
Dim lngFirst As Long
Dim lngFirstItem As Long
Dim lngI As Long
Dim lngI2 As Long
Dim lngLast As Long
Dim lngMiddle As Long
Dim lngNumEls As Long
Dim strValue As uApplication

On Error Resume Next
lngFirstItem = LBound(marrApplication)
'Subscript out of range
If Err.Number = 9 Then Exit Sub
On Error GoTo 0
lngNumEls = UBound(marrApplication)

For lngI = lngFirstItem + 1 To lngNumEls
strValue = marrApplication(lngI)
If strValue.strEXEName < marrApplication(lngI - 1).strEXEName Then
If strValue.strEXEName <> marrApplication(lngI - 1).strEXEName Then
lngFirst = lngFirstItem
lngLast = lngI - 1
Do
lngMiddle = (lngFirst + lngLast) \ 2
If marrApplication(lngMiddle).strEXEName = strValue.strEXEName Then
lngFirst = lngMiddle
Exit Do
ElseIf marrApplication(lngMiddle).strEXEName < strValue.strEXEName Then
lngFirst = lngMiddle + 1
Else
lngLast = lngMiddle - 1
End If
Loop Until lngFirst > lngLast
For lngI2 = lngI To lngFirst + 1 Step -1
marrApplication(lngI2) = marrApplication(lngI2 - 1)
Next lngI2
marrApplication(lngFirst) = strValue
End If
End If
Next lngI
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform