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
|
Public Type Fields
nom As String
prenom As String
Index As Variant
End Type
Public ind As Long
Public pFields() As Fields
Public FirstField As Fields
Public LastField As Fields
Public NextField As Fields
Sub test()
field_Add "toto", "aaaaa"
field_Add "truc", "bbbbb"
field_Add "bidule", "cccccc"
field_Add "machin", "dddddd"
field_Add "chose", "eeeee"
field_Add "titi", "fffffff"
'exemple d'utilisation avec des variables
'les variables doivent etre impérativement dimée en pfields
NextField = GetNext(FirstField)
PreviousField = GetPrevious(LastField)
'directement dans un msgbox
MsgBox FirstField.nom
MsgBox LastField.nom
MsgBox GetNext(FirstField).nom
MsgBox GetPrevious(LastField).nom
MsgBox GetFieldByIndex(10).nom
End Sub
Function field_Add(nom, prenom)
ind = ind + 1: Index = ind: ReDim Preserve pFields(0 To ind)
pFields(ind).nom = nom
pFields(ind).prenom = prenom
pFields(ind).Index = ind
If ind = 1 Then FirstField = pFields(ind)
LastField = pFields(ind)
pFields(0).nom = "existe pas"
pFields(0).prenom = "existe pas"
pFields(0).Index = "index hors limite"
End Function
Function GetNext(f As Fields) As Fields
If f.Index = UBound(pFields) Then x = 0 Else x = f.Index + 1
GetNext = pFields(x)
End Function
Function GetPrevious(f As Fields) As Fields
If f.Index <= 1 Then x = 0 Else x = f.Index - 1
GetPrevious = pFields(x)
End Function
Function GetFieldByIndex(x As Long) As Fields
If x > UBound(pFields) Or x < 1 Then x = 0
GetFieldByIndex = pFields(x)
End Function |
Partager