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 / Having Some Trouble with Arrays

Author
Message
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 10th Oct 2005 06:49 Edited at: 10th Oct 2005 17:27
Scroll Down To Next Post, Updated Question

Using DBP

Ive been working with arrays for my next project and theyre proving quite useful I've just run into this one problem I cant figure out:

Im trying to make a variable equal one of an arrays contents, and I'm trying to make the system choose which array's contents to make the variable into by using a for/next loop. However the compiler isn't liking what Im doing...bad explanation, maybe the code will help more:



I know that code seems very pointless and it is, but it's at a very basic level of what I'm trying to achieve. For some reason the system doesn't like me putting A(1) in the size dimensions, however when I use this:



Everything works fine. The only problem is when I introduce more tasks I need this to work the other way. I'm fairly new to arrays so you'll probably know more than me about them, in which case any help is great.

P.S, the error message im recieving is the old:
#100008 Parameter for 'MAKE OBJECT BOX' do not match 'Object Number, Width, Height, Depth', this error coming up on the line I used the MAKE OBJECT BOX command ofcourse.

Thanks
- RUCCUS


hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 10th Oct 2005 07:07
Your first code snippet won't work because that's not the way for/next loops work. "A" is not an array in your code so using A(1) won't work. "A" increments itself starting at the first number and ending at the last number of your for statement. So in your example, it starts at 1 and ends at 1. I'm not sure exactly what you're trying to do there, but this will work:


TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Oct 2005 07:08
The first snippet won't work because you are using the counting loop variable (A) and it isn't an array - Array#() is!

Try MAKE OBJECT BOX 1,Array#(A),Array#(A),Array#(A)

If you aren't clued up on arrays, they are covered in depth on the tutorials page of my site (link at bottom).

TDK_Man

hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 10th Oct 2005 07:09
Yeah, what he said.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Oct 2005 07:25
hyrichter

Oops sorry - didn't see your post when I did mine - otherwise I wouldn't have bothered repeating what you said!

TDK_Man

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 10th Oct 2005 16:04
Shoot I messed up the code a bit this is what I meant, Ill explain more first:

Im making a program to load objects onto a truck in the best way possible. The user enters the objects in the order they wish and the program will then load them. The user inputs the amount of the item, the width, the length, the height and the load number. These are stored in their respective variables and then dimed into an array:

DIM LoadNumber#(4)
LoadNumber#(1)=ItemAmount#
LoadNumber#(2)=ItemWidth#
LoadNumber#(3)=ItemHeight#
LoadNumber#(4)=ItemLength#

Then the LoadNumber# is increased by 1 so that array isn't overwritten:

INC LoadNumber#,1

So, if they input 10 Items, with 5 Width, 5 Length, and 15 Height, and an order or load number of 1, the array would then dim:

DIM 1(4)
1(1)=10
1(2)=5
1(3)=15
1(4)=5

I then am using two loops to create the objects with their dimensions, like so:

FOR A = 1 TO TotalTypes#
FOR B = 1 TO A(1)
IF OBJECT EXIST(B)=0 THEN MAKE OBJECT BOX B,A(2),A(3),A(4)
NEXT I
NEXT I

TotalTypes# equals the total amount of types of items, so if you had 5 chairs, 7 tables and 3 skids, the TotalTypes# variable would be set to 3.

So this system would in theory work in my head but it doesnt. My first example was bad, I think I got it all covered in this loop. Now you see that I need to have A(1) in there because A will change, it starts at 1 which is the 1st load the user specified, for example we specified 10 objects 10x5x15, so it'd make 10 of those, then A would change to 2 and it would check what the dimensions of load 2 are and make however many there are of them, and so on until all objects are created.

Sorry for the confusion, thanks for trying.


Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Oct 2005 21:15
You can have multiple numbers in a array by adding another number in the dim statment.

I would do it like this:



The 50 is the number of items you can have and the 3 is all the data for each item. LoadNumber#(0,0) would be item number 1's amount... LoadNumber@(0,1) would be item number 1's width... and so on.

Here's the breakdown:

LoadNumber#(xx,0) = Item Amount
LoadNumber#(xx,1) = Item Width
LoadNumber#(xx,2) = Item Height
LoadNumber#(xx,3) = Item Length

It looks like you don't even need the "Item Amount" data. You could either take it out or use 0 as the type of object created (ie if LoadNumber#(xx,0)=1 then create a box, if it equals 2 create a sphere, if it equals 3 create a triangle).
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 10th Oct 2005 23:24
Thanks, mnemonix cleared everything up with me over IRC I think I have it all sorted out. I might still get a problem but it should all be good for now.


Antidote
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: San Francisco, CA
Posted: 13th Oct 2005 04:57
Amazing what such a nice feature called arrays can cause even the best of programmers to mess up their programs.

I R tEh Antid0te! ROOOAAAR!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Oct 2005 07:11
Quote: "Amazing what such a nice feature called arrays can cause even the best of programmers to mess up their programs. "


If it's a human writing the program... almost anything can go wrong.

Login to post a reply

Server time is: 2024-11-27 16:58:49
Your offset time is: 2024-11-27 16:58:49