function a(b)
msgbox b.name
end functionb可能是数组变量,可能是字符串变量,也可能是字节变量,
比方
dim cc(10) as byte
cc(1)=1
call a(cc)
如何在 a中获得 参数b所引用的变量名?
------------------------------------

解决方案 »

  1.   

    变量名?应该反不回来,变量名仅仅是为了标识变量,编译以后都转换成变量在内存中的地址了。如果说要返回变量类型可以用typename()函数例子:
    Dim a() As Integer
    Dim b() As String
    Dim c() As Byte
    Dim test As VariantDebug.Print TypeName(test)
    test = a
    Debug.Print TypeName(test)
    test = b
    Debug.Print TypeName(test)
    test = c
    Debug.Print TypeName(test)输出:
    Empty
    Integer()
    String()
    Byte()
      

  2.   

    变量不是对象,哪来的Name属性
    可采用变通的方法实现:(内外约定好)
    Private Sub Command1_Click()
    Dim a() As Integer
    Dim b() As String
    Dim c() As Byte
    Test (a)
    Test (b)
    Test (c)
    End Sub
    Function Test(obj As Variant)
    Select Case TypeName(obj)
    Case "Integer()"
      MsgBox "a"
    Case "String()"
      MsgBox "b"
    Case "Byte()"
      MsgBox "c"
    End Select
    End Function
      

  3.   

    变量不是对象,哪来的Name属性言之有理~