Please run the following code:
SetWindowTitle("ttt")
SetWindowSize(1280, 800, 0)
SetVirtualResolution(1280, 800)
SetOrientationAllowed(1, 1, 1, 1)
SetPrintSize(20)
type myType
ctrlID as integer
Name as string
Value as integer
endtype
index as integer
m as myType
myArray as myType[]
CreateEditBox(1)
SetEditBoxPosition(1, 400, 21)
SetEditBoxVisible(1, 0)
CreateEditBox(2)
SetEditBoxPosition(2, 400, 41)
SetEditBoxVisible(2, 0)
index = -2
do
Print("Press [A] to add an element")
Print("Press [F] to find an element")
Print("Press [R] to remove an element")
Print("Press [ESC] to exit")
if GetRawKeyPressed(27) then end
if GetEditBoxVisible(1) = 0 and GetEditBoxVisible(2) = 0
if GetRawKeyReleased(65)
m.ctrlID = Random(1000, 2000)
m.Name = "Name" + str(Random(1, 10))
m.Value = Random(25, 50)
myArray.insert(m)
endif
if GetRawKeyReleased(70)
SetEditBoxVisible(1, 1)
SetEditBoxFocus(1, 1)
endif
if GetRawKeyReleased(82)
SetEditBoxVisible(2, 1)
SetEditBoxFocus(2, 1)
endif
else
if GetEditBoxChanged(1) = 1
m.ctrlID = Val(GetEditBoxText(1))
index = myArray.find(m.ctrlID)
SetEditBoxVisible(1, 0)
endif
if GetEditBoxChanged(2) = 1
index = Val(GetEditBoxText(2))
if index >= 0 and index <= myArray.length
myArray.remove(index)
endif
SetEditBoxVisible(2, 0)
index = -2
endif
endif
if index <> -2
Print("Search for:" + str(m.ctrlID))
Print("Found at index:" + str(index))
endif
array_Print(myArray)
Sync()
loop
function array_Print(a as myType[])
i as integer
l as integer
l = a.length
Print("")
Print("Array information")
Print("-----------------")
Print("Length:"+str(l))
if l = -1
Print("Array is empty")
exitfunction
endif
for i = 0 to l
Print("ID:" + str(a[i].ctrlID) + ", Name:" + a[i].Name + ", Value:" + str(a[i].Value))
next i
endfunction
Then add around 10 elements and try to make some searches a few times. It will not work all the times.
I am not sure if there is a bug in my code or in the find method