4

我有一个函数可以在 excel 表中显示数组的内容。我的函数的标题如下所示:

Public Sub afficher_signal(ByRef signal() As Integer, ByVal nb_ligne As Integer)

问题是有时我想用它来显示一个整数数组,有时,它是一个我想显示的双精度数组。有没有办法改变 ByRef signal() as Integer 可以接受任何类型数组的东西?

非常感谢 !

4

1 回答 1

1

代替

Public Sub afficher_signal(ByRef signal() As Integer, ByVal nb_ligne As Integer)

Public Sub afficher_signal(ByRef signal, ByVal nb_ligne As Integer)

或者

Public Sub afficher_signal(ByRef signal as Variant, ByVal nb_ligne As Integer)


下面演示了一个示例使用afficher_signal

Public Sub Main()
    Dim arr As Variant
    arr = Array(1, "yo", 3, 10 Mod 2, 5.25)
    afficher_signal arr, 0
    afficher_signal2 arr, 0
End Sub

Public Sub afficher_signal(ByRef signal As Variant, ByVal nb_ligne As Integer)
    Dim i As Long
    For i = LBound(signal) To UBound(signal)
        Debug.Print signal(i)
    Next i
End Sub

Public Sub afficher_signal2(ByRef signal, ByVal nb_ligne As Integer)
    Dim i As Long
    For i = LBound(signal) To UBound(signal)
        Debug.Print signal(i)
    Next i
End Sub
于 2013-07-23T15:33:53.837 回答