2010-10-25 83 views
2

我有以下的ASP經典功能:不明白「對象需要」錯誤

function get_children(n) 
    dim local_array 
    dim parent 
    dim path 
    if n.hasChildNodes() then 
    for each child in n.childNodes 
     local_array = array_merge(local_array, get_children(child)) 
    next 
    else 
    set parent = n.parentNode 
    while isobject(parent) 
     path = parent.nodeName & "/" & path 
     set parent = parent.parentNode 
    wend 
    path = path & "/" & get_attr(n, "file") 
    set_attr n, "path", path 
    local_array = Array(0) 
    set local_array(0) = n 
    end if 
    get_children = local_array 
end function 

在一個XML節點(從Microsoft.XMLDOM對象來)運行此,我得到的錯誤Object required: 'parent'上行

path = parent.nodeName & "/" & path 

我不明白爲什麼。我正在檢查isobject。任何人都可以解釋運行時正在抱怨什麼,爲什麼?

回答

2

當沒有更多的父節點,你會得到一個空值回,即Nothing。但是,Nothing是「空對象」,所以它也是一個對象。 IsObject(Nothing)的值是True

檢查Nothing而不是檢查,如果變量包含一個對象:

while not (parent is Nothing) 
0

我不是100%確定,但也許你應該使用/而不是IsObject?我建議嘗試IsEmpty(),IsNull()Is Nothing。後者像這樣使用:

If Not (myObject Is Nothing)