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 / Odd Array results

Author
Message
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 21st Mar 2004 19:17
Can someone take a look at the attached code and tell me whats wrong with it? It basically should print the content of the array...to my understanding the print out should beL

1
2
3
1
2
3

where in fact i'm getting

1
2
3
1
2
14511728

What's going wrong??? Have I mis-understood how an array works???
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 21st Mar 2004 19:56
Think I've sorted it....Tell me if I'm wrong, but I believe when you define an array as being (x,3) it means that you have 0-2 available for use (i.e.(x,0),(x,1),(x,2) ).....and not as I thought of being 1-3.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 21st Mar 2004 20:11
arrays are Option Base Zero, meaning indexing starts at 0 not 1. This is pervasive throughout many programming languages and is a good rule to remember early in your programming career



Home of the VB.NET Class Builder Utility - Demo available now!
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 21st Mar 2004 20:16
defining as (x,3) actually gives you (x,0), (x,1), (x,2) and (x,3).

You should never try and set a value into an invalid array position otherwise you got those weird number corruptions. DBPro won't throw an error but you will end up corrupting the array contents and possibly other variables as well!

Boo!
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 21st Mar 2004 20:17
Quote: "Think I've sorted it....Tell me if I'm wrong, but I believe when you define an array as being (x,3) it means that you have 0-2 available for use (i.e.(x,0),(x,1),(x,2) ).....and not as I thought of being 1-3."

Although arrays start from 0, that's not the problem here (Dim x(3) still goes from 0 to 3).
The issue is:
You have
Dim(200,3)
and then
rock(200,1)=1
rock(200,2)=2
rock(200,3)=3

rock(201,1)=1
rock(201,2)=2
rock(201,3)=3

Me, I'll sit and write this love song as I all too seldom do
build a little fire this midnight. It's good to be back home with you.
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 21st Mar 2004 20:33
good point spooky....that was just me making a type though....thanks for the help guys...all resolve now.

Login to post a reply

Server time is: 2024-11-26 09:50:45
Your offset time is: 2024-11-26 09:50:45