我正在用一些Visual Basic方言编写脚本。我想制作递归函数但在内部我有消息说Object var什么都没有。当我尝试在main函数中获取对象时,一切正常但在输入Sub对象后什么都不是
Private Sub Search(ByRef draw As DrawingElements)
For index0 = 0 To draw.Count
Dim subDrawing As DrawingElement
Set subDrawing = draw(index0)
If subDrawing.DrawingElements.Count<>0 Then - Here I cannot Access Count because .DrawingElements Are nothing
Search(subDrawing.DrawingElements)
End If
MsgBox(subDrawing.Type & " " & CStr(subDrawing.X) & " "& CStr(subDrawing.Y))
Next
End Sub
Sub Main
Dim App As Application
Set App = New Application
App.Show True
With App.Packages(0).ActiveSheet
Dim draw As DrawingElements
Set draw = .DrawingElements
Dim subDrawing As DrawingElement
Set subDrawing =draw(0)
MsgBox(CStr(subDrawing.DrawingElements.Count)) - Here I can acces Count and DrawingElements
Search(.DrawingElements)
End With
End Sub
我不熟悉Visual Basic,所以我不知道该怎么做。我尝试了ByRef和ByVal,我也有同样的结果。
答案 0 :(得分:0)
我用Google搜索“DrawingElements”但没有点击。使用Set App = New Application
,您可以创建一种或另一种显然具有Package和ActiveSheet的应用程序。
但是好的。显然,该工作表具有DrawingElements的集合,每个元素(DrawingElement)可以包含其他DrawingElements集合。但某处必须停止,然后该集合将为空,即其值为Nothing
。尝试:
If (subDrawing.DrawingElements Is Nothing) Then ' end of recursion
答案 1 :(得分:-1)
在VBA中,对象集合通常是从1开始的,而不是从0开始的:
For index0 = 1 To draw.Count
以及
With App.Packages(1).ActiveSheet
和
Set subDrawing =draw(1)