如何将自定义类型的数组作为参数传递给过程?
Type aa<BR> name As String<BR>End TypeSub test()<BR> Dim a() As aa 'dim a()<BR> ReDim a(1)<BR> Call addtype(a, "ok")<BR>End Sub
Sub addtype(a, str As String)<BR> Dim i As Integer<BR> ReDim Preserve a(UBound(a) + 1)<BR> With a(UBound(a))<BR> .name = str<BR> End With<BR>End Sub
请看看应该如何实现标题所述功能?
这段代码,我试过了,如果将a()定义为aa就会出错,不定义为aa就可以通过(a.name语句相应调整) 救命啊,就要沉了!!! 看下面主题我的最后复贴
<A href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=17476" target="_blank" >http://bbs.mjtd.com/forum.php?mod=viewthread&tid=17476</A> 莫大,看过了,现在问题是:"如果将a()定义为aa就会出错,不定义为aa就可以通过(a.name语句相应调整)" 我改了,现在可以了
Public Type aa<BR> name As String<BR>End Type
Sub test()<BR> Dim a() As aa 'dim a()<BR> ReDim a(1)<BR> addtype a, "ok"<BR>End Sub
Sub addtype(a() As aa, str As String)<BR> Dim i As Integer<BR> ReDim Preserve a(UBound(a) + 1)<BR> With a(UBound(a))<BR> .name = str<BR> End With<BR>End Sub<BR> 注意a要定义为全局变量或窗体的模块级变量(下面画线的语句)。
Private Type aa<BR> name As String<BR> firstrow As Integer<BR> lastrow As Integer<BR>End Type<BR>Private a() As aa
Private Sub addtype(str)<BR> Dim k As Integer<BR> k = UBound(a, 1)<BR> ReDim Preserve a(k + 1)<BR> k = UBound(a, 1)<BR> With a(k)<BR> .name = str<BR> .firstrow = a(k - 1).lastrow<BR> .lastrow = .firstrow<BR> End With<BR> Debug.Print k, a(k).name, a(k).firstrow, a(k).lastrow<BR> <BR>End Sub
<BR>Private Sub Command1_Click()<BR> <BR> ReDim a(0)
<BR> a(0).firstrow = 2<BR> a(0).lastrow = 2<BR> a(0).name = "ok"<BR> Dim i As Integer<BR> <BR> addtype "ok"<BR>End Sub 5楼的方法解决,谢谢
页:
[1]