我有一个在Excel工作表中显示数组内容的函数。我的函数的标题如下所示:
Public Sub afficher_signal(ByRef signal() As Integer, ByVal nb_ligne As Integer)
问题是有时候我想用它来显示一个Integer数组,有时我想要显示一个双数组。有没有办法改变
ByRef signal() as Integer
通过接受任何类型数组的东西?
非常感谢!
答案 0 :(得分: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