Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Type part(left As Float, top As Float, touched As Boolean, id As Int, originx As Float, originy As Float, color As Int)
Type vector(x As Double, y As Double)
Dim MultiList As List
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
MainForm.Show
MultiList.Initialize
'START ADD ALL OBJECTS TO MULTI LIST
For i = 0 To 9 'add 10 type vectors to the list
Dim v As vector
v.x = i*50
v.y = i*50
MultiList.Add(v)
Next
For j = 0 To 9 'add 10 arrays as double to the list
Dim dbl() As Double = Array As Double(j*50,j*50)
MultiList.Add(dbl)
Next
For k = 0 To 9
Dim p As part
p.id = k
p.color = fx.Colors.To32Bit(fx.Colors.Red)
p.left = k*50
p.top = k*50
p.originx = k*50
p.originy = k*50
p.touched = True
MultiList.Add(p)
Next
'END ADD ALL OBJECTS TO MULTI LIST
'CHECK IF ITEM EXITS
Dim searchv As vector
searchv.x = 3*50
searchv.y = 3*50
Log("pos: " & DynamicIndexOf(MultiList,searchv)) 'should return pos 3
Dim searchdbl() As Double = Array As Double(100,100)
Log("pos: " & DynamicIndexOf(MultiList,searchdbl)) 'should return pos 12
Dim searchp As part
searchp.id = 5
searchp.color = fx.Colors.To32Bit(fx.Colors.Red)
searchp.left = 5*50
searchp.top = 5*50
searchp.originx = 5*50
searchp.originy = 5*50
searchp.touched = True
Log("pos: " & DynamicIndexOf(MultiList,searchp)) 'should return pos 25
Dim searchdbl2() As Double = Array As Double(125,125)
Log("pos: " & DynamicIndexOf(MultiList,searchdbl2)) 'should return pos -1
End Sub
Sub DynamicIndexOf(MyList As List, Obj As Object) As Int
For i = 0 To MyList.Size - 1
Dim listobj As Object = MyList.Get(i)
If GetType(listobj) <> GetType(Obj) Then Continue
If listobj Is part And Obj Is part Then
Dim p = MyList.Get(i), pobj = Obj As part
If p.id = pobj.id And p.color = pobj.color And p.left = pobj.left And p.top = pobj.top And p.originx = pobj.originx And _
p.originy = pobj.originy And p.touched = pobj.touched Then Return i
else if listobj Is vector And Obj Is vector Then
Dim v = MyList.Get(i), vobj = Obj As vector
If v.x = vobj.x And v.y = vobj.y Then Return i
else if GetType(listobj) = "[D" Then 'Array as double
Dim d() = MyList.Get(i), dobj() = Obj As Double
If d(0) = dobj(0) And d(1) = dobj(1) Then Return i
End If
Next
Return -1
End Sub