Hi Headless JC,
I checked your code, and found the most interesting problem: I could execute it flawlessly using F5/Execute, and it passed muster under F4/Check Syntax/Compile. But it killed the DBPro compiler (as in "
send a message to Microsoft from XP because the application has encountered a hard error") when I tried to execute it in F6/Run In Debug Mode or F7/Step Through in Debug Mode (my favorite method, I might add!)
So I rolled back to the "good old days", when software coding was largely done "in the dark", relying on various printouts and/or save files to tell us what was going on under the hood.
Please forgive me, but I had to modify your code to prove that it was working properly...
Dim numberList (5)
numberList(1)=5
numberList(2)=3
numberList(3)=1
numberList(4)=4
numberList(5)=2
boxSelect = 3
` TEST CODE STARTS HERE...
`This will run through the array untill it finds number selected and then delete it
array index to top numberList()
while array index valid( numberList() )
`This was added because of * see notes below
print "Is " + str$(numberList()) + " == " + str$(boxSelect) + " (?)"
if boxSelect > 0
if numberList() = boxSelect
print " Yep - deleting element..."
array delete element numberList()
else
print " Nope - moving to next element..."
next array index numberList()
endif
endif
endwhile
`this will replace selected number to the top of the list
`* Note this was changed to at bottom to allow the box to come to the top when selected
print " ...re-adding element at bottom..."
array insert at bottom numberList()
numberList() = boxSelect
print
print
print
`print list of boxes in order
array index to bottom numberList()
while array index valid( numberList() )
print numberList()
previous array index numberList()
endwhile
`Re-Emerge into external (non-test) code...
WHILE (SCANCODE() = 0)
ENDWHILE
...simply put, your code works fine. I checked it out immediately - and if you look at this new/improved debug output, you'll see where the code runs through the array, checking each for the corrct value, before moving on. Other than trashing the compiler in the interactive modes, your code works just fine.
However, for good and all, why don't you just access the array directly? From what I can tell, you really don't need those ARRAY functions to proceess array variables, any way. For clarity, let's look at the way I would have done it:
Dim numberList (5)
numberList(1)=5
numberList(2)=3
numberList(3)=1
numberList(4)=4
numberList(5)=2
boxSelect = 3
` TEST CODE STARTS HERE...
`This will run through the array until it finds number selected and then swap it to the bottom
IF (ARRAY COUNT (numberList()) > 1)
FOR xCnt = 1 TO (ARRAY COUNT (numberList()) - 1)
IF (numberList(xCnt) = boxSelect)
` Swap the selected item to the bottom of the list...
numberList(xCnt) = numberList(ARRAY COUNT (numberList()))
numberList(ARRAY COUNT (numberList())) = boxSelect
EXIT ` Exit the Loop
ENDIF
NEXT xCnt
ENDIF
`this will replace selected number to the top of the list
`* Note this was changed to at bottom to allow the box to come to the top when selected
print
print
print
`print list of boxes in order
array index to bottom numberList()
while array index valid( numberList() )
print numberList()
previous array index numberList()
endwhile
`Re-Emerge into external (non-test) code...
WHILE (SCANCODE() = 0)
ENDWHILE
While it may not accomplish exactly what you were intending, it performs the same function as the previous code, but faster. Mind you, it's just a suggestion: the fun thing about programming is that there are millions of ways to accomplish a task - and none of them are wrong. (They all accomplish the same task! If the task is accomplished, then victory is established!)
Interstingly enough, my new code also crashes the debugger/single-stepper. Oh, well, it works in the runtime...
Hope this helps!!!
LongFist
SuperProgrammer For Hire