您看这样定义可以不?
public function arrFun(ByRef arr() as string) as array()???我想返回一个数组?
Dim i as integer
i=10
redim arr(1 to i)
..
..
End function
2.如何调用该函数?
Dim retArr() as string
retArr()=arrFun(array()??) ,这样写可以不?数组参数该如何写?
7 个解决方案
#1
很有用的问题,我也想知道答案
关注
人总是要成长的,让我们大家一起在CSDN里成长为新一代的高手吧!
想吵架的人闪一边去,我们只来学习,不学习的请安静!!!
关注
人总是要成长的,让我们大家一起在CSDN里成长为新一代的高手吧!
想吵架的人闪一边去,我们只来学习,不学习的请安静!!!
#2
用Variant
在函数内部定义一个数组,函数返回为Variant
最后把数组赋值给函数。
在函数内部定义一个数组,函数返回为Variant
最后把数组赋值给函数。
#3
如果不行,就用自定义类型来做。
自定义类型可以实现未知维数和深度的多维数组.
这是我多年vb的心得.
看下面代码(自定以类型要放到模块里声明)
type aa
bb() as string
end type
sub s_xxx(s as aa)
dim sreturn as aa
redim sreturn.bb(n)
sreturn.bb(0)=s.bb(0)
sreturn.bb(1)=s.bb(1)
……
end sub
自定义类型可以实现未知维数和深度的多维数组.
这是我多年vb的心得.
看下面代码(自定以类型要放到模块里声明)
type aa
bb() as string
end type
sub s_xxx(s as aa)
dim sreturn as aa
redim sreturn.bb(n)
sreturn.bb(0)=s.bb(0)
sreturn.bb(1)=s.bb(1)
……
end sub
#4
你可以修改一下变的更完善.
Private Sub Command1_Click()
Dim f(2) As Long
f(0) = 0
f(1) = 1
f(2) = 2
Dim b As Variant
b = a(f)
Dim i
For i = 0 To UBound(b)
Debug.Print b(i)
Next
End Sub
Function a(ByRef aa() As Long) As Variant
If IsArray(aa) Then
Dim i As Long
For i = 0 To UBound(aa)
aa(i) = aa(i) + 1
Next i
a = aa
End If
End Function
Private Sub Command1_Click()
Dim f(2) As Long
f(0) = 0
f(1) = 1
f(2) = 2
Dim b As Variant
b = a(f)
Dim i
For i = 0 To UBound(b)
Debug.Print b(i)
Next
End Sub
Function a(ByRef aa() As Long) As Variant
If IsArray(aa) Then
Dim i As Long
For i = 0 To UBound(aa)
aa(i) = aa(i) + 1
Next i
a = aa
End If
End Function
#5
可以定义成类,将数组数据放到内部的数组变量里面就可以了
#6
'数组aryTest是用作函数的输入参数的
Private aryTest(10) As Long
Private Sub Command1_Click()
Dim lngI As Long
Dim aryShow As Variant
'以下两句反映根据输入参数类型的不同返回对应的值
aryShow = ReturnAry(aryTest)
'aryShow = ReturnAry(0)
'如果返回值是数组就把它们的值显示出来
If IsArray(aryShow) Then
For lngI = LBound(aryShow) To UBound(aryShow)
MsgBox aryShow(lngI), vbInformation, lngI
Next
Else
MsgBox "Not array", vbInformation
End If
End Sub
Private Sub Form_Load()
Dim lngI As Long
'初始化输入数组
For lngI = LBound(aryTest) To UBound(aryTest)
aryTest(lngI) = 10 - lngI
Next
End Sub
'输入和输出的数组都用Variant类型来实现
Private Function ReturnAry(AryInput As Variant) As Variant
'输入参数是数组就把值赋给函数名
If IsArray(AryInput) Then
ReturnAry = AryInput
Else
ReturnAry = Null
End If
End Function
Private aryTest(10) As Long
Private Sub Command1_Click()
Dim lngI As Long
Dim aryShow As Variant
'以下两句反映根据输入参数类型的不同返回对应的值
aryShow = ReturnAry(aryTest)
'aryShow = ReturnAry(0)
'如果返回值是数组就把它们的值显示出来
If IsArray(aryShow) Then
For lngI = LBound(aryShow) To UBound(aryShow)
MsgBox aryShow(lngI), vbInformation, lngI
Next
Else
MsgBox "Not array", vbInformation
End If
End Sub
Private Sub Form_Load()
Dim lngI As Long
'初始化输入数组
For lngI = LBound(aryTest) To UBound(aryTest)
aryTest(lngI) = 10 - lngI
Next
End Sub
'输入和输出的数组都用Variant类型来实现
Private Function ReturnAry(AryInput As Variant) As Variant
'输入参数是数组就把值赋给函数名
If IsArray(AryInput) Then
ReturnAry = AryInput
Else
ReturnAry = Null
End If
End Function
#7
新斑竹终于出现了?出次见面,以后还请多多指教!
#1
很有用的问题,我也想知道答案
关注
人总是要成长的,让我们大家一起在CSDN里成长为新一代的高手吧!
想吵架的人闪一边去,我们只来学习,不学习的请安静!!!
关注
人总是要成长的,让我们大家一起在CSDN里成长为新一代的高手吧!
想吵架的人闪一边去,我们只来学习,不学习的请安静!!!
#2
用Variant
在函数内部定义一个数组,函数返回为Variant
最后把数组赋值给函数。
在函数内部定义一个数组,函数返回为Variant
最后把数组赋值给函数。
#3
如果不行,就用自定义类型来做。
自定义类型可以实现未知维数和深度的多维数组.
这是我多年vb的心得.
看下面代码(自定以类型要放到模块里声明)
type aa
bb() as string
end type
sub s_xxx(s as aa)
dim sreturn as aa
redim sreturn.bb(n)
sreturn.bb(0)=s.bb(0)
sreturn.bb(1)=s.bb(1)
……
end sub
自定义类型可以实现未知维数和深度的多维数组.
这是我多年vb的心得.
看下面代码(自定以类型要放到模块里声明)
type aa
bb() as string
end type
sub s_xxx(s as aa)
dim sreturn as aa
redim sreturn.bb(n)
sreturn.bb(0)=s.bb(0)
sreturn.bb(1)=s.bb(1)
……
end sub
#4
你可以修改一下变的更完善.
Private Sub Command1_Click()
Dim f(2) As Long
f(0) = 0
f(1) = 1
f(2) = 2
Dim b As Variant
b = a(f)
Dim i
For i = 0 To UBound(b)
Debug.Print b(i)
Next
End Sub
Function a(ByRef aa() As Long) As Variant
If IsArray(aa) Then
Dim i As Long
For i = 0 To UBound(aa)
aa(i) = aa(i) + 1
Next i
a = aa
End If
End Function
Private Sub Command1_Click()
Dim f(2) As Long
f(0) = 0
f(1) = 1
f(2) = 2
Dim b As Variant
b = a(f)
Dim i
For i = 0 To UBound(b)
Debug.Print b(i)
Next
End Sub
Function a(ByRef aa() As Long) As Variant
If IsArray(aa) Then
Dim i As Long
For i = 0 To UBound(aa)
aa(i) = aa(i) + 1
Next i
a = aa
End If
End Function
#5
可以定义成类,将数组数据放到内部的数组变量里面就可以了
#6
'数组aryTest是用作函数的输入参数的
Private aryTest(10) As Long
Private Sub Command1_Click()
Dim lngI As Long
Dim aryShow As Variant
'以下两句反映根据输入参数类型的不同返回对应的值
aryShow = ReturnAry(aryTest)
'aryShow = ReturnAry(0)
'如果返回值是数组就把它们的值显示出来
If IsArray(aryShow) Then
For lngI = LBound(aryShow) To UBound(aryShow)
MsgBox aryShow(lngI), vbInformation, lngI
Next
Else
MsgBox "Not array", vbInformation
End If
End Sub
Private Sub Form_Load()
Dim lngI As Long
'初始化输入数组
For lngI = LBound(aryTest) To UBound(aryTest)
aryTest(lngI) = 10 - lngI
Next
End Sub
'输入和输出的数组都用Variant类型来实现
Private Function ReturnAry(AryInput As Variant) As Variant
'输入参数是数组就把值赋给函数名
If IsArray(AryInput) Then
ReturnAry = AryInput
Else
ReturnAry = Null
End If
End Function
Private aryTest(10) As Long
Private Sub Command1_Click()
Dim lngI As Long
Dim aryShow As Variant
'以下两句反映根据输入参数类型的不同返回对应的值
aryShow = ReturnAry(aryTest)
'aryShow = ReturnAry(0)
'如果返回值是数组就把它们的值显示出来
If IsArray(aryShow) Then
For lngI = LBound(aryShow) To UBound(aryShow)
MsgBox aryShow(lngI), vbInformation, lngI
Next
Else
MsgBox "Not array", vbInformation
End If
End Sub
Private Sub Form_Load()
Dim lngI As Long
'初始化输入数组
For lngI = LBound(aryTest) To UBound(aryTest)
aryTest(lngI) = 10 - lngI
Next
End Sub
'输入和输出的数组都用Variant类型来实现
Private Function ReturnAry(AryInput As Variant) As Variant
'输入参数是数组就把值赋给函数名
If IsArray(AryInput) Then
ReturnAry = AryInput
Else
ReturnAry = Null
End If
End Function
#7
新斑竹终于出现了?出次见面,以后还请多多指教!