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
| Option Explicit
Private Tableau() As Integer
Private Const max As Integer = 30
Private Sub Form_Load()
' Initialise le tableau
Dim i As Integer
For i = 0 To max
ReDim Preserve Tableau(i)
Tableau(i) = i
Next
End Sub
Private Sub Command1_Click()
' AfficherTableau UBound(Tableau), Tableau, Text1
AfficherTableau UBound(Tableau), Tableau, Picture1
' AfficherTableau UBound(Tableau), Tableau, List1
End Sub
Private Sub AfficherTableau(N As Integer, T() As Integer, O As Object)
Dim i As Integer
If TypeOf O Is TextBox Then
If O.MultiLine And O.ScrollBars > 1 Then
With O
.Text = T(i)
For i = 1 To N
.Text = .Text & vbCrLf & T(i)
Next
End With
End If
ElseIf TypeOf O Is PictureBox Then
' Une méthode avec O.Print
' plus complexe à mettre en oeuvre
' parce qu'un picture box n'a pas de scrollbar.
' J'ai donc usé d'un stratagème tordu.
' Pour l'instant, arrête à 29.
On Error Resume Next
O.Cls
For i = 0 To N Step 5
O.Print T(i); T(i + 1); T(i + 2); T(i + 3); T(i + 4)
Next
ElseIf TypeOf O Is ListBox Then
' méthode la plus simple
O.Clear
For i = 0 To N
O.AddItem T(i)
Next
Else
MsgBox "Composant d'affichage non valide.", vbExclamation, "Erreur"
End If
End Sub |
Partager