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