Option Explicit Private Type V D As String: Deb As String: Fin As String: Lib As String End Type Private TabLigne() As V Private Sub Trier(Liste As ListBox) Dim arrBuf() As V, I As Long, Col As Variant, lngDecalage As Long Liste.Clear For I = LBound(TabLigne) To UBound(TabLigne) Liste.AddItem TabLigne(I).D & "*" & TabLigne(I).Deb & "@" & I Next ReDim arrBuf(LBound(TabLigne) To UBound(TabLigne)) For I = LBound(arrBuf) To UBound(arrBuf) Col = Split(Liste.List(I - LBound(arrBuf)), "@", 2) arrBuf(I) = TabLigne(Col(1)) Next TabLigne = arrBuf End Sub Private Sub RemplirTableau() Dim I As Long ReDim TabLigne(1 To 255) For I = 1 To 255 Randomize TabLigne(I).D = Int(Rnd * 9999) + 1 Randomize TabLigne(I).Deb = Int(Rnd * 9999) + 1 Next End Sub Private Sub AfficherResultats() Dim I As Long For I = LBound(TabLigne) To UBound(TabLigne) List1.AddItem TabLigne(I).D & " - " & TabLigne(I).Deb Next End Sub Private Sub Form_Load() RemplirTableau Trier lstTriage AfficherResultats End Sub
Dim l As Long: Do Until l -1: l l + 1: Loop
Private Type V D As String Deb As String Fin As String Prog As String Lib As String End Type Dim TabLigne(15) As V Private Sub Command1_Click() List1.Clear For i = 0 To 15 For k = 1 To Len((TabLigne(i).D)) pp = pp & Asc(Mid$((TabLigne(i).D), k, 1)) Next k For j = i + 1 To 15 For k = 1 To Len((TabLigne(j).D)) aa = aa & Asc(Mid$((TabLigne(j).D), k, 1)) Next k If pp < aa Then mm = TabLigne(j).D TabLigne(j).D = TabLigne(i).D TabLigne(i).D = mm End If aa = "" Next j Next i For i = 0 To 15 List1.AddItem TabLigne(i).D Next i End Sub Private Sub Form_Load() For i = 0 To 15 TabLigne(i).D = i & "-12" List1.AddItem TabLigne(i).D Next i End Sub
Dim l As Long: Do Until l -1: l l + 1: Loop
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Type V StrDate As Date StrDebut As Date StrFin As String StrCha As String End Type Dim Tabligne(0 To 5) As V Private Sub Form_Load() Tabligne(0).StrDate = "26/06" Tabligne(0).StrDebut = "12:30" Tabligne(0).StrFin = "12:55" Tabligne(0).StrCha = "TF1" Tabligne(1).StrDate = "26/06" Tabligne(1).StrDebut = "11:30" Tabligne(1).StrFin = "12:59" Tabligne(1).StrCha = "C+" Tabligne(2).StrDate = "29/06" Tabligne(2).StrDebut = "02:30" Tabligne(2).StrFin = "02:55" Tabligne(2).StrCha = "ARTE" Tabligne(3).StrDate = "26/06" Tabligne(3).StrDebut = "22:30" Tabligne(3).StrFin = "02:55" Tabligne(3).StrCha = "TF1" Tabligne(4).StrDate = "29/06" Tabligne(4).StrDebut = "01:30" Tabligne(4).StrFin = "02:55" Tabligne(4).StrCha = "F3" Tabligne(5).StrDate = "26/06" Tabligne(5).StrDebut = "00:10" Tabligne(5).StrFin = "02:55" Tabligne(5).StrCha = "F2" 'Affichage du tableau dans list1 non trié Call affiche(List1) End Sub Private Sub Command1_Click() '1 Trie par date '=============== Dim temp As V Do nb = 0 DoEvents For i = 0 To UBound(Tabligne) - 1 If Tabligne(i).StrDate > Tabligne(i + 1).StrDate Then temp.StrDate = Tabligne(i).StrDate temp.StrDebut = Tabligne(i).StrDebut temp.StrFin = Tabligne(i).StrFin temp.StrCha = Tabligne(i).StrCha Tabligne(i).StrDate = Tabligne(i + 1).StrDate Tabligne(i).StrDebut = Tabligne(i + 1).StrDebut Tabligne(i).StrFin = Tabligne(i + 1).StrFin Tabligne(i).StrCha = Tabligne(i + 1).StrCha Tabligne(i + 1).StrDate = temp.StrDate Tabligne(i + 1).StrDebut = temp.StrDebut Tabligne(i + 1).StrFin = temp.StrFin Tabligne(i + 1).StrCha = temp.StrCha nb = nb + 1 End If Next i Loop Until nb = 0 '2 Trie par Heure de debut '========================= Dim var As Date i = 0 While i < UBound(Tabligne) lemin = i var = Tabligne(i).StrDate 'on recup l'indice de la derniere date pareil While Tabligne(i).StrDate = var And i < UBound(Tabligne) i = i + 1 Wend lemax = i - 1 Do nb = 0 For j = lemin To lemax - 1 If Tabligne(j).StrDebut > Tabligne(j + 1).StrDebut Then temp.StrDate = Tabligne(j).StrDate temp.StrDebut = Tabligne(j).StrDebut temp.StrFin = Tabligne(j).StrFin temp.StrCha = Tabligne(j).StrCha Tabligne(j).StrDate = Tabligne(j + 1).StrDate Tabligne(j).StrDebut = Tabligne(j + 1).StrDebut Tabligne(j).StrFin = Tabligne(j + 1).StrFin Tabligne(j).StrCha = Tabligne(j + 1).StrCha Tabligne(j + 1).StrDate = temp.StrDate Tabligne(j + 1).StrDebut = temp.StrDebut Tabligne(j + 1).StrFin = temp.StrFin Tabligne(j + 1).StrCha = temp.StrCha nb = nb + 1 End If Next j Loop Until nb = 0 i = lemax + 1 Wend 'Affichage du tableau trié par date et par heure Call affiche(List2) End Sub Sub affiche(Src As ListBox) Src.Clear For i = 0 To UBound(Tabligne) With Tabligne(i) Src.AddItem .StrDate & " " & .StrDebut & " " & .StrFin & " " & .StrCha End With Next i End Sub