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 / Problem with REPEAT or array

Author
Message
aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 17th Nov 2009 21:38
Hi all, anybody see anything wrong with this code?



Every time I run this I get

"Runtime Error 118 Array does not exist or out of bounds at line 16"

The file is a simple text file containing a line of data with a space as the delimiter.

Russell B. Davis/aerostudios
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 17th Nov 2009 21:53 Edited at: 17th Nov 2009 21:54
It would help if you would attach the text file so we can test it.
But, are there more than 8 words in the first string of the text file you are parsing,
you have only dimmed the array to 8 and line 16 may exceed the 8 array elements.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Nov 2009 21:54
I'#d guess that your simple file has more than 8 fields in it

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Nov 2009 22:07
Seems to work fine for me.

How many items have you got on a line?
aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 17th Nov 2009 22:10 Edited at: 17th Nov 2009 22:13
Here is the first few lines of the text file;

ID X Y HDG USE AIRLINE ALT 1 ALT 2
D1 -295.05 -736.28 220 CIV NA NA NA
D2 -305.99 -726.02 220 CIV NA NA NA
D3 -316.93 -715.76 220 CIV NA NA NA
D4 -327.88 -705.5 220 CIV NA NA NA
D5 -364.61 -671.04 220 CIV NA NA NA
D6 -375.56 -660.78 220 CIV NA NA NA
D7 -386.5 -650.52 220 CIV NA NA NA
D8 -397.44 -640.25 220 CIV NA NA NA
D9 -408.38 -629.99 220 CIV NA NA NA
D10 -419.32 -619.73 220 CIV NA NA NA
V1 225.97 -139.05 0 CIV NA NA NA
V2 210.97 -139.05 0 CIV NA NA NA

It is saved as a TXT file and there are no spaces past the 8 elements on each line. Is it the CR/LF possibly the cuplrit? I increased the array to 10 elements instead of 8, and it worked.

The first line is a header, and I simply throw it away; that's why its called 'trash$' in the beginning. So the extra space between ALT 1 and ALT 2 is not the problem. Even if I remove that line, I experience the problem.

Russell B. Davis/aerostudios
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Nov 2009 22:17
It's because you try to access tempitem$(9) BEFORE testing whether you have reached the end of the line:

aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 17th Nov 2009 22:23
Ahha,, thanks. I'm new to this REPEAT command so I don't quite have my understanding of it. Added an IF B$<>"" before adding to the array and that fixed it.

Russell B. Davis/aerostudios
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Nov 2009 22:28
There are two basic conditional loops in DBPro:

while <condition>
endwhile

and

repeat
until <condition>

In the while loop the condition is tested BEFORE the loop commands are executed.

In the repeat loop the condition is tested AFTER the loop commands are executed.
aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 17th Nov 2009 23:02
I appreciate it very much. I come from a VB background, so some of these DBPro commands are not quite the same. Thanks!

Russell B. Davis/aerostudios

Login to post a reply

Server time is: 2026-06-11 03:55:47
Your offset time is: 2026-06-11 03:55:47