/ / Le sous-appel VBA donne «erreur de compilation: incompatibilité de type: tableau ou type défini par l'utilisateur attendu» - tableaux, excel-vba, passage d'arguments, vba, excel

Le sous-appel VBA donne “erreur de compilation: correspondance de type: type de tableau ou défini par l'utilisateur attendu” - tableaux, excel-vba, transmission d'arguments, vba, excel

J'ai 2 Subs, les deux reçoivent un tableau comme argument. l'un fonctionne bien, l'autre donne: erreur de compilation: incompatibilité de type: tableau ou type défini par l'utilisateur attendu. Dans le code écrit ci-dessous, "InitializeArray" fonctionne et "PresentTotalRow" ne fonctionne pas. Quelqu'un peut-il comprendre pourquoi?

Sub PresentTotalRow(nCells As Integer, totalProductsPerDay() As Integer)
row = nCells + MatrixRowOffset + 2
Range(Cells(row, 2), Cells(row, 8)) = totalProductsPerDay
End Sub

Sub InitializeArray(ByRef arr() As Long)
Dim N As Long
For N = LBound(arr) To UBound(arr)
arr(N) = 0
Next N
End Sub


Sub ReadTxtFile()
.....

Dim totalProductsPerDay(0 To 6) As Long
InitializeArray totalProductsPerDay

Dim filePath As String
filePath = "C:workDocumentsinput.txt"

Dim oFS As TextStream
If oFSO.FileExists(filePath) Then

Set oFS = oFSO.OpenTextFile(filePath)
......
i = 1
Do While Not oFS.AtEndOfStream

line = oFS.ReadLine
....
nCells = calcNCells

totalProductsCounter = GetTotalProductsCounter()
totalProductsPerDay(Day) = totalProductsPerDay(Day) + totalProductsCounter

i = i + 1
Loop

PresentTotalRow nCells, totalProductsPerDay
oFS.Close
Else
MsgBox "The file path is invalid.", vbCritical, vbNullString
Exit Sub
End If

Exit Sub

End Sub

Merci, Li

Réponses:

1 pour la réponse № 1
Sub PresentTotalRow(nCells As Integer, totalProductsPerDay() As Integer)
row = nCells + MatrixRowOffset + 2
Range(Cells(row, 2), Cells(row, 8)) = totalProductsPerDay
End Sub

le deuxième argument attend un tableau entier

PresentTotalRow nCells, totalProductsPerDay

vous passez un long tableau ici comme deuxième argument