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 / learning the basic questions

Author
Message
glyvin101
19
Years of Service
User Offline
Joined: 27th Jan 2005
Location:
Posted: 2nd Jun 2005 12:07
Hi

I have just got done learning about loops i bought the DBP book and I was wondering what the purpose of the DIM command is i really dont understand it..

Thx

glyvin101
waffle
22
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 2nd Jun 2005 12:17
it instructs the compiler to reserve system memory for your data.
That's why arrays are global in scope. Example:

dim Stuff#(4,4)

reserves a 5 by 5 array of floating point numbers.
Floats take up 4 bytes each, so total usage is
4*5*5 or 100 bytes.
glyvin101
19
Years of Service
User Offline
Joined: 27th Jan 2005
Location:
Posted: 2nd Jun 2005 12:18
still dont understand it much i am not very understanding of arrays and dims

thx for trying tho
D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 2nd Jun 2005 13:08 Edited at: 2nd Jun 2005 13:12
The DIM is short for DIMension. This is used to define an array size. Okay let's back up for a minute. An array is a variable with and index number or numbers in parethesis which can have multiple dimesions or just a single dimesion.

Does this sound confusing? Let me explain more in detail.

Let say you have a list of names and you want to store them as a variable. You know what a variable is right? Well, okay. You could do the following...



Notice that I used four different variables to store the names. To make things easier and have fewer variables, you would use an ARRAY.



The code above uses only one variable indexed, in this case a single array variable, to store the names. This makes it easier than using multiple variables. The DIM statement was used to define and array size of 4 elements or names.

You might ask why would someone would want to use an ARRAY? Well for many reasons. What if there were more than four names, how about a hundred or a thousand? You wouldn't want to use that many variables to store each name. You would only need one, an array variable. This simplifies situations where you need to manipulate the data stored in an array.



Mulitiple dimesions are possible too. Let's say you want to add a
last name. You could use a 2-dimensional array.



Or,



You can have three, four, or more dimesions as well. Think of an array as a filing cabinet. Each drawer is an array variable. Each folder in that drawer is an element containing information concerning that array. In my example, that array was names$(4) or names$(4,2).

Does this answer you question?
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 2nd Jun 2005 13:35
@glyvin101

D Ogre did a good job in explaining arrays. I just want to add one thing to it.

(Although this can be confusing), it's important to understand at some point; that in DBC/DBpro...

When Dimensioning arrays, the first element's index is 0 and the last element index is the number in the dim command.

So...

Dim name$(4)

Actually reserves room for five elements

name$(0)
name$(1)
name$(2)
name$(3)
name$(4)

Sometimes for simplicity sake, people disregard index 0.

~zen

glyvin101
19
Years of Service
User Offline
Joined: 27th Jan 2005
Location:
Posted: 2nd Jun 2005 13:52
THx i almost completely understand it now u guys are awesome
waffle
22
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 3rd Jun 2005 13:15 Edited at: 3rd Jun 2005 13:16
sorry,
guess I was too brief
glyvin101
19
Years of Service
User Offline
Joined: 27th Jan 2005
Location:
Posted: 3rd Jun 2005 13:55
nah i am just to stupid
D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 4th Jun 2005 11:25
Your right about dimesioning an array creates the first index in the array as 0, Zen. Thanks for mentioning it for me. I forgot...

Login to post a reply

Server time is: 2024-09-23 21:23:30
Your offset time is: 2024-09-23 21:23:30