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.

DarkBASIC Professional Discussion / Searching an array

Author
Message
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 9th Jun 2003 05:48
I have an array of size 100. Lets call it MyArray$(100). It contains strings. I can't work out how to check the array to see what is the next available slot. I've tried this:

FOR i = 1 TO 100
IF MyArray$(i) = "" THEN MyArray$(i) = "whatever"
NEXT i

But it doesn't work. I figured that an empty slot in an array would be "". Basically, I am trying to keep track of the strings entered by the user and the easiest way I think is to search the array itself. Can somebody please help?
Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 9th Jun 2003 08:06
once you find your first free slot, you'll need to stop searching. Otherwise this loop will continue on to fill ALL the empty solts through the array with "whatever"



FOR i = 1 TO 100
IF MyArray$(i) = "" THEN MyArray$(i) = "whatever": EXIT
NEXT i

l8r,
Kevin Picone
[url]www.underwaredesign.com[/url]
ToXic
23
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Australia
Posted: 9th Jun 2003 10:44
Still uwdesign, the code below should end the program.

dim t$(10)
if t$(0) = "" then end
do
loop

or this.

if t$ = "" then end
do
loop


ToXic
ToXic
23
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Australia
Posted: 9th Jun 2003 10:48
FieldDoc try this.

if len(t$(t)) = 0 then exit


ToXic
Andy Igoe
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 9th Jun 2003 11:33


Pneumatic Dryll
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jun 2003 14:09
It's the old 'null pointer' string problem raising it's head again.

To see what I mean, put this code into a new project and run it:



The fix is simple - just add "" to the string you are testing:



FieldDoc: Just use this instead

FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 9th Jun 2003 15:21
Thanks guys...really appreciated. Can I ask one more related question?

Supposing I have my this array called MyArray$(100) and I have been sequentially adding strings to it. What I want to do is that once the array gets filled, I want to move all the positions down one.
So,

If MyArray$(100) has got a string in it....this signifies that the array is full. What I want to do is delete what is in MyArray$(1) and move what was in MyArray(2) into MyArray$(1) and so on. This will in effect, allow me to add the next string to MyArray$(100) but preserving all the other strings (except for the oldest one).

Does this make sense? I would appreciate your inputs fellas

Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jun 2003 15:40 Edited at: 9th Jun 2003 15:42
I'd love to tell you to use the array handling commands, but the one that deletes from the top doesn't work , so you hjave to do this manually.

FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 9th Jun 2003 16:57
Is that the wrong way round? That will shift what is in MyArray$(1) to MyArray$(2). I need something that will delete what is in MyArray$(1) and move what is in MyArray$(2) into MyArray$(1), what is in MyArray$(3) will get moved into MyArray$(2) and so on....all the way up so that MyArray$(100) gets put into MyArray$(99), therefore meaning that MyArray$(100) will be empty...thus allowing me to add another string to the array.

Sorry for any confusion IanM

Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
ToXic
23
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Australia
Posted: 9th Jun 2003 17:25
FieldDoc look at his code a bit closer, you have what you asked for i think.

ToXic.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jun 2003 18:08
'tis indeed Try it and you'll see.

When the ARRAY DELETE ELEMENT command is fixed, you'll be able to do this:

ARRAY DELETE ELEMENT MyArray$(),1
ARRAY INSERT AT BOTTOM MyArray$()
MyArray$(100)=NewStuff$
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 9th Jun 2003 20:43
My bad....sorry for doubting!

Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.

Login to post a reply

Server time is: 2026-07-11 11:42:19
Your offset time is: 2026-07-11 11:42:19