1

我在vba,excel中有以下代码。首先,我创建了类“列表”:

Public next as List
Public val as Integer

接下来我想做这样的事情

Sub Test()
    Dim ls as List
    Set ls = new List

     Set_val ls.next, 8
     Debug.Print (ls.next is Nothing) 'True - why?
     Debug.Print ls.next.val 'Error
end sub


Sub Set_val(l as List, v as Integer)
     Set l = new List
     l.val = v
end sub

但它不起作用,我收到错误消息“未设置块变量的对象或变量”。你知道它应该如何正确完成吗?

4

2 回答 2

1

试试这个:

Sub Test()
    Dim ls as List
    Set ls = new List

     Set ls.Next = Set_val(8)
     Debug.Print (ls.next is Nothing) 'True - why?
     Debug.Print ls.next.val 'Error
end sub

Function Set_val(v as Integer) as List
    Set Set_val = new List
    Set_val.val = v
end sub
于 2013-07-20T18:36:53.853 回答
0

Public next As List不能工作,因为Next不能用。

你永远不会改变next. 该函数改为更改 的值val

我不明白您要做什么,但这应该会有所帮助:

Sub Test()
    Dim ls As List
    Set ls = New List

     Set_val ls, 8
     Debug.Print (ls.next0 Is Nothing) 'True - why?
     Debug.Print ls.next0.val 'Error
End Sub

Sub Set_val(l As List, v As Integer)
     Set l.next0 = New List
     l.val = v
End Sub
于 2013-07-20T21:17:03.113 回答