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
| Public obj1 As New obj
Public obj2 As New obj
Public resultat As Integer
main obj1, obj2, resultat
'programme principal
Public Sub main(ByRef new_obj1 As obj, ByRef new_obj2 As obj, ByRef resultat As Integer)
def_objet new_obj1, new_obj2 'on caractérise les objets
utilisation_objet new_obj1, new_obj2, resultat 'on travaille avec les objets
Debug.Print resultat 'on affiche le résultat
End Sub
Sub def_objet(ByRef new_obj1 As obj, ByRef new_obj2 As obj)
new_obj1.attribut1 = 3
new_obj2.attribut1 = 5
End Sub
Sub utilisation_objet(ByRef new_obj1 As obj, ByRef new_obj2 As obj, ByRef resultat As Integer)
resultat = somme_objet(new_obj1, new_obj2)
End Sub
Public Function somme_objet(ByRef new_obj1 As obj, ByRef new_obj2 As obj) As Integer
somme_objet = new_obj1.attribut1 + new_obj2.attribut1
End Function
et la classe obj:
Private PVattribut1 As Integer
Public Property Let attribut1(ByVal new_attribut1 As Integer)
PVattribut1 = new_attribut1
End Property
Public Property Get attribut1() As Integer
attribut1 = PVattribut1
End Property |
Partager