mikewolf2k 发表于 2004-3-8 21:15:00

如何将自定义类型的数组作为参数传递给过程?

Type aa<BR>                                                                                       name As String<BR>End Type


Sub 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语句相应调整)

mikewolf2k 发表于 2004-3-10 20:46:00

救命啊,就要沉了!!!

莫名 发表于 2004-3-10 21:15:00

看下面主题我的最后复贴


<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>

mikewolf2k 发表于 2004-3-10 21:27:00

莫大,看过了,现在问题是:"如果将a()定义为aa就会出错,不定义为aa就可以通过(a.name语句相应调整)"

my_computer 发表于 2004-3-10 21:46:00

我改了,现在可以了


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>

莫名 发表于 2004-3-10 22:03:00

注意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

mikewolf2k 发表于 2004-3-10 22:06:00

5楼的方法解决,谢谢
页: [1]
查看完整版本: 如何将自定义类型的数组作为参数传递给过程?