Bonjour,
archaos a écrit :Sachant que le tableau est déclaré comme suit:
Peut-être ainsi :
Code : Tout sélectionner
Sub Main
REM Déclaration du tableau
Dim tableau(5,1) as Double
REM Initialisation du tableau
tableau(0, 0) = 0
tableau(1, 0) = 1
tableau(2, 0) = 2
tableau(3, 0) = 3
tableau(4, 0) = 4
tableau(5, 0) = 5
REM tableau(6, 0) = 15 ' Erreur : Out of range
tableau(0, 1) = 6
tableau(1, 1) = 7
tableau(2, 1) = 8
tableau(3, 1) = 9
tableau(4, 1) = 10
tableau(5, 1) = 11
REM tableau(6, 1) = 51 ' Erreur : Out of range
Print maSomme(tableau, 0) ' somme de la dimension 1, soit 15 = 0+1+2+3+4+5
Print maSomme(tableau, 1) ' somme de la dimension 2, soit 51 = 6+7+8+9+10+11
End Sub
Sub maSomme(t as Array, nCol as Integer) as Double
Dim i as Integer
maSomme = 0
For i=0 to UBound (t) ' Equivalent à UBound (t, 1) ou 1 represente la dimension 1 du tableau soit 5
maSomme = maSomme + t(i, nCol)
Next i
End Sub
N.B. : Je n'ai pas trouvé dans la doc(
BASIC_Guide/Arrays) comment initialiser un tableau sur une ligne.
Si tu souhaite déclarer un tableau de tableau comme suit :
Tu peux écrire ta fonction ainsi:
Code : Tout sélectionner
Sub Main
Dim mTableau(1) REM equivalent à mTableau(0 To 1)
aColA = Array(0, 1, 2, 3, 4, 5)
aColB = Array(6, 7, 8, 9, 10, 11)
mTableau(0) = aColA
mTableau(1) = aColB
Print mySum(mTableau, 0)
Print mySum(mTableau, 1)
End Sub
Sub mySum(t, nCol as Integer) as Double
Dim i as Integer
mySum = 0
For i=0 to UBound (t(nCol))
mySum=mySum + t(nCol)(i)
Next i
End Sub
Je ne suis pas sur de ce que je dis. Je débute a écrit :En résumé : Pour accéder a une colonne d'un tableau/matrice tout dépend de la façon dont tu a déclarer ta variable.
myArray(nRow)(nCol)
myMatrix(nRow, nCol)
Bien à vous,
Fred