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 / Brand new to programming and in need of help with arrays.

Author
Message
Gorrath
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Fort Huachuka, Arizona
Posted: 24th Sep 2004 04:07
Greetings all. On a recent trip into Hasting's I picked up DarkBasic thinking it would be a great outlet for my RPG creating tendancies. I have never programmed a thing in my life and was a bit overwhlemed when I started browsing through the manual.

Five hours of programming later and I think I'm doing alright however I have reached an impass. I didn't like the final product of some of the tutorials and so started adding pieces of code the tutorial didn;t call for in order to make the programs better. However I'm now stuck on tutorial five and can't seem to get my head around the problem. The program itself is meant to access an array and allow a user to input changes to various parts of it. The part I am having trouble with is providing a feature to allow the user to see two sets of data from the array multipled by eachother.

Here is the code I've written for that feature and the error code I am receiving.

CLS
For c=1 TO 5
Companies(c,1)*Companies(c,2)=A
Print A
Next c

Error Code: Runtime Error at line 36. Array accessed out of bounds.

My problem is stemming from the fact that while I understand what certain parts of code actually do, I am still bewildered by why they do it. I'm not sure if I've included enough code for you guys to understand what's causing the error, but I will post more if need be. Thank you for your time and attention to a struggling programmer.

I am drowning in a sea of code. Code code everywhere and not a drop to drink.
TravisP
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location: Behind you, with a knife!
Posted: 24th Sep 2004 07:41
This should fix it you forgot to DIM the array.
Dim Companies(5,5)



empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 24th Sep 2004 07:48
Yes you need to set the dimension of an array before you use it. Also if you want to put the result of Companies(c,1)*Companies(c,2) in variable A, then it's the other way around:
A = Companies(c,1)*Companies(c,2)

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
X_MEN
21
Years of Service
User Offline
Joined: 14th Sep 2003
Location:
Posted: 24th Sep 2004 07:56
hope this help

You can do it if you try
Gorrath
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Fort Huachuka, Arizona
Posted: 24th Sep 2004 08:12
Firstly let me thank you guys for replying, always nice to know there are people out there willing to help a total beginer.

To Travis: I only posted a small portion of the total code, the array was perviously set using: DIM Companies(5,2). Several other of my FOR c=1 to 5 ect. codes work it just seems this one dosn't. I'll post the whole code here so you guys can get a full view of what I'm doing. (Or I hope so)

To Empty: I hadn't thought of that because I didn't realize the side made a difference. If you wouldn't mind explaining it to me a bit what is the difference, from a programming perspective between these two lines of code:

Companies(c,1)*Companies(c,2)=A

A=Companies(c,1)*Companies(c,2)

Here is the full code for the program:

I am drowning in a sea of code. Code code everywhere and not a drop to drink.
Gorrath
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Fort Huachuka, Arizona
Posted: 24th Sep 2004 08:53
Just wanted to add an update; Changing the code to A=Companies(c,1)*Companies(c,2) worked and the totals are now being printed properly. I am very happy that it works but I am still confused as to the difference between the two codes, from a mathematical perspective there isn't a difference so why is it the programming language sees a difference? Knowing details such as this seems important to me so I can know when to have the variable on one side or the other.

Also, I will put a new copy of my code in here and anyone who wishes to please provide constructive criticism as to how I could have coded certain parts of it better or how I could have streamlined the program as a whole. Any information would be a great help and appreciated.

I am drowning in a sea of code. Code code everywhere and not a drop to drink.
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 24th Sep 2004 09:33
There is a very huge difference...in programming, the variable that you are inputing your data into comes first. The data that you want to be inputed comes second. Examples:

This will set the variable A equal to a value of 5:
A=5

This will set the varialbe B equal to a value of 10:
B=10

This will set the variable C equal to a value of 50, because A and B have been previously defined.
C=B*A

Now, if you do this:
A=B
It will set A equal to whatever B is, and B will be unaffected.

If you do this:
B=A
It will set B equal to whatever A is, and A will be unaffected.

The variable that is being changed is always on the left side, and there is always only one variable on the left. The other stuff goes on the right:
A=speed*cos(angle)+original_velocity*cos(angle)

I hope I helped, do you understand?

Xander Moser - Bolt Software - Firewall
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 24th Sep 2004 09:43
the result is always passed to the left side of the equation

Result = operations/functions/etc


DBP_NETLIB_v1.4.3 DarkTOPIA site coming soon!
Gorrath
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Fort Huachuka, Arizona
Posted: 24th Sep 2004 09:43
Well it seems the code I entered into the code area of the forum message did not appear in either of my posts, anyone know what might have happened to it? I assumed it would become a snipit button like I've seen in other posts around the boards but alas...

Have a new question as well, while working on another tutorial it had me splitting a bitmap into several seperate images and then pasting them into their neibbors sector then looping it so the pices of bitmap rotate in a clockwise motion. I managed to figure out how to speed up and slow down the rotation as well as reverse it's direction, however when I tried to break the image into 1/16th's instead of 1/4's it gave me an error code:

Runtime Error The File Does Not Exist.

Now the coideline it highlighted was the first in the series of lines that breaks up the bitmap into seperate images so I double checked that I had input the correct coordinates for each gridsquare to be isolated and pasted and it seemed correct. I used the same format for isolating pieces of the bitmap ie:

The tutorial codeline for the first 1/4was: GET IMAGE 0,0,320,240
The codeline I entered for the fist 1/16th was: GET IMAGE 0,0,160,120
No other changes were made to the code with the exception of the parts that further broke up the image into 1/16th squares and the code that should cause those new smaller blocks to rotate. Any ideas where I could have gone wrong? Sorry that I can't seem to post code snipits I'm sure that would help you guys help me.

I am drowning in a sea of code. Code code everywhere and not a drop to drink.
Gorrath
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Fort Huachuka, Arizona
Posted: 24th Sep 2004 09:57
Thank you very very much your explanations helped me tremendously and I understand completly. The more help I get that's as well written and concise as that the less I'll be drowing in this sea of code.

PS: Sorry whichever mod is being forced to read all these posts I keep submitting, I would have just done some of them as edits to my other posts but as each post has a lag time as it is reviewed when each post will actually be posted. My appologies.

I am drowning in a sea of code. Code code everywhere and not a drop to drink.
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 24th Sep 2004 19:05
my eyes, my eyes! , just kidding

If no-one gives your an answer to a question you have asked, consider:- Is your question clear.- Did you ask nicely.- Are you showing any effort to solve the problem yourself

Login to post a reply

Server time is: 2024-11-27 10:36:43
Your offset time is: 2024-11-27 10:36:43