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 / Array help please

Author
Message
yr un olaf
18
Years of Service
User Offline
Joined: 28th May 2006
Location:
Posted: 28th May 2006 17:11
Hi
I am trying to write a program that writes intagers into an (almost if its not possible) infinite array and then can test the last five entered integers in the array to see if there is a number missing.

For example if the numbers 1,2,2,1,2 are put into the array then i want to test if it has and 1's 2's or 3's in those last 5 places and then return a message saying that there are no 3's

I have been trying to think of how to do this but am struggling so would be grateful for any help. I'm sure its very simple and i'm just being thick but oh well
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 28th May 2006 18:12 Edited at: 28th May 2006 18:15
iirc the ArrayCount() function will return the upperbound index of the array, then you can use that value, -1, -2, -3, -4 to get the last 5 elements in the array

say you had 10 items in the array, the arraycount would be 9 (elements start at 0, so your array is 0-9 (10 elements))

so something like:
iUB = arraycount(your_array)

iVal1 = your_array(iub)
iVal2 = your_array(iub-1)
iVal3 = your_array(iub-2)
iVal4 = your_array(iub-3)
iVal5 = your_array(iub-4)

Just be sure iUB is => 4 before doing the above, if the element doesn't exist it will go boom. Im sure theres a bunch of different ways to do what you want, the above is just one

In general I'd be careful about growing an array over the life of the app, could get dodgy if it gets too big and eats your memory

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th May 2006 23:25
dim array(10) technically makes 11 elements in DB, 0-10. You can assign a value to the 0th index, but array count doesn't count that. So I just ignore 0 and use 1-10.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 29th May 2006 16:14
if you have an array with 1 element (position 0) does arraycount return 1 or 0?

if it returns 0 then its returning the Upper Bound Index, and the code above will work

if it returns 1, the actual count (like the name implies) then the code above will need to be tweaked off by 1

I dont have dbp installed so I couldnt check this

Login to post a reply

Server time is: 2024-11-26 19:52:23
Your offset time is: 2024-11-26 19:52:23