我有一個字符串列表,像這樣的數組:VBScript來從線陣列創建樹
1=xItem
2=xInstance
3=xVersion
4=xValue
2=pInstance
3=pVersion
1=yItem
2=yInstance
2=zInstance
3=zVersion
4=zValue
我有一個類定義是這樣的:
Class InfoEntry
Public Name
Public infoList
Private Sub Class_Initialize()
set infoList= CreateObject("System.Collections.ArrayList")
End Sub
End Class
我想有樹結構像這樣:
Root
-xItem
-xInstance
-xVersion
-xValue
-pInstance
-pVersion
-yItem
-yInstance
-zInstance
-zVersion
-zValue
最初的要求只能達到兩個級別。但現在深度可能會有所不同。
我已經編寫了如下的邏輯,它只適用於兩個層次的深度。如果需要的話,我可以把我的代碼放在這裏。但它的瑕疵。我想有更好的版本。我很抱歉,我不擅長VBScript。
我不擅長VBScript,所以試圖找到VB中的邏輯。
Function GetTree(NodeName,FileLines,counter)
Call WriteToLog(LOG_AL_NIINFO, "started creating Tree structure for Node " & NodeName, False)
Dim OEntry
Set OEntry = New InfoEntry
OEntry.Name=NodeName
Dim StringTree,Stack
set StringTree = CreateObject("System.Collections.ArrayList")
set Stack = CreateObject("System.Collections.ArrayList")
dim i,curr
For i=0 To (FileLines.Count-1)
set curr=FileLines(i)
call Stack.Add(curr)
if (i+1) < (FileLines.Count-1) then
if InStr(FileLines(i+1),counter & "=") = 1 then
call StringTree.Add(Stack)
set Stack= CreateObject("System.Collections.ArrayList")
end if
end if
Next
StringTree.Add(Stack)
If StringTree.Count > 0 Then
For Each collection in StringTree
If collection.Count > 0 Then
dim TopNode
set TopNode=collection(0)
call collection.Remove(TopNode)
dim splitKey,rootKey
set splitKey=Split(TopNode,"=")
rootKey=splitKey(1)
call OEntry.infoList.Add(GetTree(rootKey,collection,(counter+1)))
End if
Next
End If
Call WriteToLog(LOG_AL_NIINFO, "Finsihed creating Tree structure for Node " & NodeName, False)
if VMS_GCO_Structure.Exists(NodeName) = false And OEntry.infoList.Count <> 0 then
call VMS_GCO_Structure.Add(NodeName,OEntry)
end if
GetTree=OEntry
end function
我得到空引用錯誤與此。有人可以建議我在哪裏做錯了嗎?
編輯你的問題,併發布你到底作爲代碼嘗試過什麼! – Hackoo
done..code added..but added but but not working as per expectation .. – VyshuRam