Error in Global Dim I hope not.

Previous topic - Next topic

spudgunjake

I am getting a Strange error with Global Dim Arrays

I define the arrays up out side my main but the strings in a external gbas file. I can put anything to array 0.

FUNCTION ARRAY_WORDS :

   A_WORD_LIST$[ 0]="First"      // error in arrays
   A_WORD_LIST$[ 1]="TEST"

ENDFUNCTION

Print A_WORD_LIST$[ 0], 0, 0  // prints TEST not FIRST

I have to do is this to get around this error.

   A_WORD_LIST$[ 0]=" "      // Space, if I leave this like "" if print FIRST as it was cell 0.
   A_WORD_LIST$[ 1]="FIRST"
   A_WORD_LIST$[ 2]="TEST"

print A_WORD_LIST$[ 1], 0, 0  //  prints FIRST

so all my for next loops have to start from 1 not 0,

any ideas

Neurox

Are you sure to have declared correctly the variable ?

I've wrote this sample and running ok
Code (glbasic) Select

// --------------------------------- //
// Project: testarray
// Start: Sunday, December 27, 2009
// IDE Version: 7.206
LOCAL i
GLOBAL A_WORD_LIST$[]
DIM A_WORD_LIST$[2]

ARRAY_WORDS()
FOR i = 0 TO 1
   PRINT A_WORD_LIST$[i],0,i*10
NEXT

SHOWSCREEN
KEYWAIT

FUNCTION ARRAY_WORDS :

   A_WORD_LIST$[ 0]="First"     
   A_WORD_LIST$[ 1]="TEST"

ENDFUNCTION

Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

matchy

I suggest placing code in a code block

It hard to tell whether the error is due to the leading space in the brackets:
Code (glbasic) Select
A_WORD_LIST$[ 0]

Should be:
Code (glbasic) Select
A_WORD_LIST$[0]


spudgunjake

your example worked but, and a big but.

I have to 2 list of words, lets say A_WORD and B_WORD, If I setup B_WORD first the error still their in B list not displaying cell 0  but this time A_WORD list is correct.

to correct the problem if have to add A_WORD_LIST[0]="A_WORD its doing me head in" at the end of the A_WORD  list once more.

To make matter worse if i do this


A_WORD_LIST[0]=" "
A_WORD_LIST[1]="A"
A_WORD_LIST[2]="B"
A_WORD_LIST[3]="C"

PRINT A_WORD_LIST[0] ,0,0
PRINT A_WORD_LIST[1],0,20
PRINT A_WORD_LIST[2],0,40
PRINT A_WORD_LIST[3],0,60

i GET

B
B
C

but if I put A_WORD_LIST[0]=" " at the end I get


A
B
C

Believe me this isn't difficult code.

spudgunjake

I have just taken out the A_Word LIST of the the external gbas file and inserted it in the main routine and it works. but this does help me.

if i print A_WORD_LIST$[0] I get whats in that cell, also if I print the list out it prints correctly.

Any ideas,

Moru

Give us the full code and let's have a look at it. The whole thing with project-folder and everything in a zipfile since you have more than one source-file there.

MrTAToad

And what version are you using ?

spudgunjake

I got it to work, But it has open a new cam of worms.

It was down to a sprite, I have a mixture jpg, png, and bmp. One of the bmp was corrupt I believe or GLBASIC doen't like a mixture of file types.

when I placed the A_WORD_LIST routine before the sprite load routine it worked, but if it was after the  Load Sprite routine it wouldn't.

Converted all the sprite to png and its working fine for now.  Many thanks for the help guys. Great software wished I found sooner a lot easer then COCO2d