1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Const LB_ADDSTRING = &H180
Private Const LB_RESETCONTENT = &H184
Private Const CB_ADDSTRING = &H143
Private Const CB_RESETCONTENT = &H14B
Private nombre As Long
Private Sub Form_Activate()
nombre = 50000
Dim i As Long, mode As String, depart As Double
Do While mode <> "0" And mode <> "1"
mode = InputBox("choisissez le mode (0 = String ou 1 = integer")
Loop
Select Case mode
Case 0
'================================================================================================================
' DEMO SUR TABLEAU DE STRINGS
'================================================================================================================
ReDim tableaustring(nombre) As String
For i = 0 To nombre
tableaustring(i) = "coucou " & i
Next
MsgBox "nous allons maintenant lancer successivement les 2 méthodes pour ce tableau de" & vbCrLf & _
"S T R I N G s" & vbCrLf & _
"et mesurer leur durée d'exécution"
'-----------------------------------------méthode classique-----------------------------------------------------
Combo1.Clear
depart = Timer
Combo1.Visible = False
For i = 0 To nombre
Combo1.AddItem tableaustring(i)
Next
Combo1.Visible = True
MsgBox "durée de " & Timer - depart & " par la méthode classique"
'--------------------------------------méthode par SendMessage---------------------------------------------------
Combo1.Clear
depart = Timer
tableau_vers_box Combo1, tableaustring
MsgBox "durée de " & Timer - depart & " par la méthode SendMessage"
Case 1
'================================================================================================================
' DEMO SUR TABLEAU DE INTEGERS
'================================================================================================================
ReDim tableauinteger(nombre + 1) As Long
For i = 0 To nombre
tableauinteger(i) = i
Next
MsgBox "nous allons maintenant lancer successivement les 2 méthodes pour ce tableau de" & vbCrLf & _
"I N T E G E R s" & vbCrLf & _
"et mesurer leur durée d'exécution"
'-----------------------------------------méthode classique-----------------------------------------------------
Combo1.Clear
depart = Timer
Combo1.Visible = False
For i = 0 To nombre
Combo1.AddItem tableauinteger(i)
Next
Combo1.Visible = True
MsgBox "durée de " & Timer - depart & " par la méthode classique"
'--------------------------------------méthode par SendMessage---------------------------------------------------
Combo1.Clear
depart = Timer
tableau_vers_box Combo1, tableauinteger
MsgBox "durée de " & Timer - depart & " par la méthode SendMessage"
End Select
End Sub
Sub tableau_vers_box(ctrl As Object, T As Variant)
Dim i As Long, mess As Long, handle As Long
If TypeOf ctrl Is ComboBox Then
mess = CB_ADDSTRING
ElseIf TypeOf ctrl Is ListBox Then
mess = LB_ADDSTRING
Else
Exit Sub
End If
handle = ctrl.hWnd
For i = LBound(T) To UBound(T)
SendMessage handle, mess, 0, ByVal CStr(T(i))
Next
End Sub |
Partager