Node Naming Scheme for oobn

Dim vbafactory As New HVBA
Public cellX As Integer
Public cellY As Integer

'When creating a runtime domain from a Class, all nodes
'are named by concatenating the names of the nodes in the
'list of source nodes(for source nodes see GetSource())
'using a dot character(‘.’) as seperator.

'This naming scheme makes it easy to work with the
'nodes in the runtime domain, as one can use the dot
'naming convention when calling GetNodeByName(String).

' Write the program output to a Worksheet named "Output"
Public Sub WriteToWorksheet(text As String)
    Dim output As Worksheet
    On Error Resume Next
    Set output = Sheets("Output")
    On Error GoTo 0
    output.Cells(cellY, cellX) = text
End Sub

' Select File Dialog
Public Function SelectFile() As String
    Dim intChoice As Integer
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    fd.AllowMultiSelect = False
    intChoice = fd.Show
    If intChoice <> 0 Then
        SelectFile = fd.SelectedItems(1)
    End If
End Function

' Print the name of each node in the list.
Public Sub PrintNodes(list As nodeList)

    For Each Node In list
        WriteToWorksheet (Node.GetName)
        cellX = cellX + 1
    Next
    cellY = cellY + 1

End Sub

' Load a hugin Object Oriented Bayesian Network,
' unfold classes to a domain and print out the node names.
Public Sub Main()

    cellX = 1
    cellY = 1
    Dim output As Worksheet
    On Error Resume Next
    Set output = Sheets("Output")
    On Error GoTo ErrorHandler
    If output Is Nothing Then
        Sheets.Add().Name = "Output"
    Else
        Sheets("Output").Cells.Clear
    End If
    oobnFile = SelectFile
    Dim cc As ClassCollection
    Set cc = vbafactory.ClassCollection
    Dim plstn As New DefaultClassParseListener
    Call cc.ParseClasses(oobnFile, plstn)
    Dim myClass As Class
    Set myClass = cc.GetClassByName(oobnFile)
    If myClass Is Nothing Then
        cellY = 1
        cellX = 1
        WriteToWorksheet ("Class is NULL")
    Else
        For Each c In cc.GetMembers
            WriteToWorksheet ("Nodes in class: " & c.GetName)
            cellY = cellY + 1
            PrintNodes (c.GetNodes)
        Next
        cellY = cellY + 1
        WriteToWorksheet ("Nodes in runtime domain:")
        cellY = cellY + 1
        Dim Dom As Domain
        Set Dom = myClass.CreateDomain
        Call PrintNodes(Dom.GetNodes)
        Dom.Delete
        cc.Delete
    End If

Exit Sub
ErrorHandler:
    Call MsgBox("An Error Occurred in your Script" & vbNewLine & TypeName(vbafactory.lastExceptionHugin) & vbNewLine & vbafactory.lastExceptionHugin.Message, vbCritical, "Error")

End Sub
Close