请高手帮忙:在VB里面,函数FUNCTION可不可以返回数组。因为我的程序中,有很多重复代码,想用写一个函数或过程,但返回值需要是数组,我该怎么办?

解决方案 »

  1.   

    '显式声明返回字符串数组
    function RtArray() as string()
    end function
    '返回变体类型,也可以返回数组
    function RtVariant() 
    end function
      

  2.   

    当然可以。
    Private Sub Command1_Click()
    Dim strArr() As String
    strArr = abc("123", "456")
    MsgBox strArr(0)
    End SubPublic Function abc(a As String, b As String) As String()
    Dim temp(1) As Stringtemp(0) = a
    temp(1) = b
    abc = temp
    End Function
      

  3.   

    Option ExplicitPrivate Sub Form_Load()
        Dim s() As String
        s = fun
        MsgBox s(0)
        MsgBox s(1)
        MsgBox s(2)
    End SubPrivate Function fun() As Variant
        Dim s(2) As String
        s(0) = "a"
        s(1) = "b"
        s(2) = "C"
        fun = s
    End Function
      

  4.   

    ReDim 可以动态分配数组大小
    UBound 可以返回数组大小