'显式声明返回字符串数组 function RtArray() as string() end function '返回变体类型,也可以返回数组 function RtVariant() end function
当然可以。 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
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
function RtArray() as string()
end function
'返回变体类型,也可以返回数组
function RtVariant()
end function
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
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
UBound 可以返回数组大小