bfelger
03-31-2005, 08:13 PM
I hope this is the right forum for a VBScript question (I figure you guys work with VBScript everyday). I'm new to VBScript (normally a C coder, so not having pointers is killing me ;) ), and I'm trying to create a simple digraph (with each node having a many-to-many relationship with other nodes) using OOP (each node is an object) in VBScript. I start with a class much like this one:
Class A
Private List ' List of nodes connected to
Public Count ' # of nodes connected to
Public Data
Private Sub Class_Initialize()
Dim List(0) ' We'll grow it as we need to
Count = 0
End Sub
' Create the bidirectional link
Public Sub BiLink(a)
UniLink(a)
a.UniLink(Me)
End Sub
' Create a unidirectional link
Public Sub UniLink(a)
Redim List(Count+1)
Set List(Count) = a
Count = Count + 1
End Sub
Public Function GetFromList(index)
Set GetFromList = List(index)
End Function
End Class
This class works if I only link two objects:
Set a1 = new A
Set a2 = new A
a1.Data = "a1!!"
a2.Data = "a2!!"
a1.BiLink(a2)
For i = 0 To a1.Count-1
Set temp = a1.GetFromList(i)
Print/Msg/Whatever a1.Data & " contains " & temp.Data
Next
But fails when I link a third object to the first like so:
Set a1 = new A
Set a2 = new A
Set a3 = new A
a1.Data = "a1!!"
a2.Data = "a2!!"
a3.Data = "a3!!"
a1.BiLink(a2)
a1.BiLink(a3)
For i = 0 To a1.Count-1
Set temp = a1.GetFromList(i)
Print/Msg/Whatever a1.Data & " contains " & temp.Data
Next
The error occurs in the "GetFromList" method; it says that the array element referenced isn't an object!
Class A
Private List ' List of nodes connected to
Public Count ' # of nodes connected to
Public Data
Private Sub Class_Initialize()
Dim List(0) ' We'll grow it as we need to
Count = 0
End Sub
' Create the bidirectional link
Public Sub BiLink(a)
UniLink(a)
a.UniLink(Me)
End Sub
' Create a unidirectional link
Public Sub UniLink(a)
Redim List(Count+1)
Set List(Count) = a
Count = Count + 1
End Sub
Public Function GetFromList(index)
Set GetFromList = List(index)
End Function
End Class
This class works if I only link two objects:
Set a1 = new A
Set a2 = new A
a1.Data = "a1!!"
a2.Data = "a2!!"
a1.BiLink(a2)
For i = 0 To a1.Count-1
Set temp = a1.GetFromList(i)
Print/Msg/Whatever a1.Data & " contains " & temp.Data
Next
But fails when I link a third object to the first like so:
Set a1 = new A
Set a2 = new A
Set a3 = new A
a1.Data = "a1!!"
a2.Data = "a2!!"
a3.Data = "a3!!"
a1.BiLink(a2)
a1.BiLink(a3)
For i = 0 To a1.Count-1
Set temp = a1.GetFromList(i)
Print/Msg/Whatever a1.Data & " contains " & temp.Data
Next
The error occurs in the "GetFromList" method; it says that the array element referenced isn't an object!