IonicWind Software

IWBasic => General Questions => Topic started by: AndrewB on December 06, 2006, 10:14:18 PM

Title: Strange array data...
Post by: AndrewB on December 06, 2006, 10:14:18 PM
Hello,
I have a multi-dimensional array [8,8] that is not behaving and is driving me crazy.
The odd bit is this. After I add a value to [0,0] the bottom row [0,8] to [8,8] have values in them.

There is only one line in my code that does the variable setting to the array and debugging the 'cell' position about to be written gets no where near the bottom row.

  >:( and  ??? and a bit of,  :'(

has anyone else experienced this?

-A(b)



Edit :

Just to add to the confusion, The number I assign to [0,0] is a random number using, Rand(11,20). When I debug out the entire array, the extra numbers I get on the bottom row are either 1, 9 and sometimes a 3


Edit 2 :

Run this through....


Def array[8,8] As INT
Def number, zz As INT

number = Rand(11,20)

array[0,0] = number

For zz = 0 to 8
debugprint LTrim$(Str$(array[0,zz])) + " | " + LTrim$(Str$(array[1,zz])) + " | " + LTrim$(Str$(array[2,zz])) + " | " + LTrim$(Str$(array[3,zz])) + " | " + LTrim$(Str$(array[4,zz])) + " | " + LTrim$(Str$(array[5,zz])) + " | " + LTrim$(Str$(array[6,zz])) + " | " + LTrim$(Str$(array[7,zz])) + " | " + LTrim$(Str$(array[8,zz]))
Next zz


Is it something to do with the 0 based indexing?


Edit x:

Ok, strike that, I need to go one larger in both directions on the initial array size....  ::)
Title: Re: Strange array data...
Post by: Haim on December 06, 2006, 11:43:04 PM
I am no expert but If I am not mistaken, your array is dimensioned to have 8 elements while in your loop you try to access 9 elements
0 to 8 ...

see the documentation.

Haim
Title: Re: Strange array data...
Post by: Ionic Wind Support Team on December 07, 2006, 05:05:51 AM
A dimension of 8 has 8 indexes 0 - 7, arrays in Emergence are zero based.
Title: Re: Strange array data...
Post by: J B Wood (Zumwalt) on December 07, 2006, 06:25:53 AM
Like Haim and Paul said, your real array is only 0-7, the 8'th element is trash data.
Here was the results with your code:

Starting debug session...
15 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7
8 | 15 | 8650752 | 0 | 8658784 | 0 | 0 | 0 | 0


The last line is trash, its bogus information pulled from what ever is in memory at the time.
Only rows 0-7 have valid information in them.
Title: Re: Strange array data...
Post by: AndrewB on December 07, 2006, 06:32:52 AM
Thanks, I was realising that as i was posting,  :-[ hence all the edits to the first post. Amazing what happens when you talk out loud.  :)
cheers,

Andrew
Title: Re: Strange array data...
Post by: J B Wood (Zumwalt) on December 07, 2006, 06:34:00 AM
Try this instead:


Def array[8,8] As INT
Def number, zz As INT
def yy as int
string output

For zz = 0 to 7
for yy = 0 to 7
number = Rand(11,20)
array[zz,yy] = number
output = output + LTrim$(Str$(array[zz,yy])) + " | "
next yy
debugprint output
output = ""
Next zz


Should give results like this: (different numbers of course)

20 | 14 | 12 | 17 | 16 | 19 | 17 | 11 |
14 | 14 | 20 | 17 | 16 | 19 | 14 | 17 |
12 | 14 | 20 | 11 | 11 | 11 | 19 | 16 |
19 | 19 | 15 | 15 | 16 | 18 | 17 | 16 |
12 | 11 | 15 | 17 | 17 | 11 | 19 | 15 |
11 | 12 | 11 | 19 | 12 | 16 | 11 | 19 |
14 | 15 | 13 | 18 | 19 | 14 | 11 | 19 |
20 | 18 | 14 | 13 | 18 | 12 | 16 | 18 |