Bonjour,

J'ai tenté de créer une dll en VB.NET afin de pouvoir l'utiliser sous VBA (Excel)
Tout se passe bien jusqu'à l'appel d'une méthode de mon objet : Erreur VBA = Argument ou appel de procédure incorrect. C'est la première fois que je touche au .NET et aux DLL donc j'ai certainement omis certaines choses, mais je ne trouve pas.
La classe VB.NET permet simplement le calcul de médiane sur des tableaux à 1 ou 2 dimensions. (Le code fonctionne en VB.NET).
Je sais bien que la fonction mediane existe sous VBA mais c'est un premier code de test.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Public Class Stats
 
    Public Function Mediane(ByRef tabValue() As Double) As Double
        Dim tabSize As Long
        Mediane = 0
        If Not IsNothing(tabValue) AndAlso tabValue.Length > 0 Then
            Array.Sort(tabValue)
            tabSize = tabValue.Length
            If tabSize Mod 2 = 0 Then
                Mediane = (tabValue(tabSize / 2 - 1) + tabValue(tabSize / 2)) / 2
            Else
                Mediane = tabValue((tabSize + 1) / 2 - 1)
            End If
        End If
    End Function
 
 
    'TabCriteria et TabValue doivent être de même taille
    Public Function Mediane(ByRef tabValue(,) As Double) As Double
 
        Dim tabCalcul() As Double
        Dim i As Long, j As Long, k As Long, n As Long, m As Long
 
        Mediane = 0
 
        ' - Test vacuité tabCriteria
        If IsNothing(tabValue) Then Exit Function
 
        ' - Construction tableau 1D
        n = UBound(tabValue, 1) + 1
        m = UBound(tabValue, 2) + 1
        ReDim tabCalcul(m * n - 1)
        k = 0
        For i = 0 To n - 1
            For j = 0 To m - 1
                tabCalcul(k) = tabValue(i, j)
                k = k + 1
            Next j
        Next i
 
        ' - Calcul
        Mediane = Mediane(tabCalcul)
 
    End Function
 
    Public Sub TestMediane()
        Debug.Print(Mediane({{1, 2, 3, 4}, {1, 2, 3, 4}}))
        Debug.Print(Mediane({1, 2, 3, 4, 5}))
    End Sub
 
End Class
et voici le code VBA qui plante à mon grand désespoir
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
Sub TestMediane()
 
    Dim oStats As New Stats.Stats
    Dim i As Integer, mediane As Double
    Dim tabTest(1 To 4) As Double
 
    For i = 1 To 4
        tabTest(i) = i
    Next i
    mediane = oStats.mediane(tabTest)  'plante ici
    Debug.Print mediane
 
End Sub
J'espère que vous pourrez m'aider car je n'ai pas trouvé grand chose sur le net.
Merci d'avance.