Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Using an array to create a list which you can then change the order of

Author
Message
Jac
20
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 27th Sep 2004 04:56
Sorry for the long title but this one has me stumped.

To start with I was doing really well, I had a problem, looked in the manual for help found some interesting array commands that I thought could help. Looked us some examples on the forum which IanM had kindly placed in the codebase and it worked. as shown below.



This created the interchangeable list I was after. But I got cocky thought this bit of code



was a little untidy and realised I could replace it with



and it still worked which felt good. Then I realised I could remove



because it wasn't needed any longer, leaving me with



which works perfectly except it adds an unwanted zero at the top of the list. Now as this is a learning exercise can anyone tell me why this has happened.

Thanks

JC
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Sep 2004 06:14
so what is it that you're trying to do exactly?

"eureka" - Archimedes
Jac
20
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 27th Sep 2004 23:16
Sorry, let me explain more clearly.

The first code snippet above returns a list of 1, 2, 3 which when each of these numbers are pressed they go to the top. Eg isf you press 2 then the order would be 2, 1, 3

The last code snippet above does the same but adds a zero to the start of the list. 0, 1, 2, 3

I was woundering if anyone could tell what the diference is between these two code snippets that allows the unwanted zero to appear.

Hope thats a little clearer.

JC
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 28th Sep 2004 00:37 Edited at: 28th Sep 2004 00:40
The extra zero gets added because,

First time through the do loop

`this will replace selected number to the top of the list
array insert at top numberList()
numberList() = number#

number# = 0
so 0 is added to the top of the list.

Second time through the do loop

`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() )
if numberList() = number#
array delete element numberList()
else
next array index numberList()
endif
endwhile

number# = 0 so the 0 at the top of the list is deleted then

`this will replace selected number to the top of the list
array insert at top numberList()
numberList() = number

number# = 0 so it is added to the top of the list agian.

Also you shouldn't use floats (variables with # suffix) to store integer numbers.

it's cool to hate
Jac
20
Years of Service
User Offline
Joined: 9th Nov 2003
Location:
Posted: 28th Sep 2004 03:37
Thanks, now I understand. I forgot that number# = 0 when no other value is given to number#.

Also thanks for the last tip, still getting used to variables.

JC

Login to post a reply

Server time is: 2024-09-23 01:26:13
Your offset time is: 2024-09-23 01:26:13