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 / Understanding - DIM?

Author
Message
KARRIBU
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: England
Posted: 8th Oct 2003 01:40
Hello.

Can you please help me out with understanding the DIM command? I understand that it's used for setting global variables, and I have the beginers guide to programming in DB, but the example given is not really explained well.

Regards.
Andy.

I wouldn't be so paranoid if people would just stop looking at me!
skovron
21
Years of Service
User Offline
Joined: 14th Sep 2003
Location:
Posted: 8th Oct 2003 01:56
Hello.
DIM command isnt for setting global variables. Its for declaring arrays.

dim myArray(10) as integer
will declare array myArray containing 11 integers indexed from 0 to 10. Then you can assaign integer values to array cells like this:
myArray(0) = 5
myArray(4) = 1000
and so...

This term of setting global variables is probably becouse arrays are visible from inside functions (have global scope) but thats another story
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Oct 2003 03:35
factoid:

DIM comes from "DIMENSION" (DIM) command in BASIC, telling the compiler how much space to allocate for a variable, usually a string:

DIM A$(20) would let the string A$ hold 20 characters.

zzzzzzz

-RUST-
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Oct 2003 15:43
Wrong! That would allocate 21 strings from A$(0) through to A$(20).
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Oct 2003 17:34 Edited at: 8th Oct 2003 17:37
Sheesh IanM, quick to drop the "wrong!" smack down, eh? Well I have no way of checking now but I am pretty sure Atari 400 BASIC DIM statement was not Option Base Zero - but I could be wrong. Can anyone else here say for sure?

EDIT: Ian I just reread your post and you, my friend, are WRONG! I may not have qualified the statement earlier but in ATARI 400 BASIC you defined a SINGLE string variable with a DIM statement, stating how many characters to hold (pretty sure option base 1) - so I stand by my original post - but would submit I should have been more clear on the lang version.

-RUST-
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 8th Oct 2003 22:24
@CattleRustler - you are right about Atari 400 basic, see here (http://www.cyberroach.com/analog/an11/strings.htm)

IanM was of course talking about DBPro, not about Atari BASIC...

If your mansion house needs haunting, just call Rentaghost!
Saikoro
20
Years of Service
User Offline
Joined: 6th Oct 2003
Location: California
Posted: 8th Oct 2003 22:36
I use dim commands to shorten things up in my codes. Using that in combonation with for...next statements can greatly reduce space in your code. However, only use this combo if you have the same type of command going through multiple times... example
dim name$(4)
name$(1)="Hello"
name$(2)="Goodbye"
name$(3)="Up"
name$(4)="Down"

for i = 1 to 4
print name$(i)
next i

This will print the four strings. Its a lot shorter than printing each individual thing out, especially when you have more complex commands. Hope I helped u out.
-Mathew Larribas

*Currently working on : Untitled RPG
*Working with : Smokiemcpot
*Percent done: .5%
KARRIBU
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: England
Posted: 8th Oct 2003 22:50
Yes, that's cleared things up nicely thanks people. So in that last example. if it were:

For i = 1 to 3
print name$(i)
next i

it would print:
Hello
Goodbye
Up

Is that right?

I wouldn't be so paranoid if people would just stop looking at me!
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 8th Oct 2003 23:03
Thats right.


Avatar & Logo by Indi. Insert witty comment here...
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Oct 2003 23:38
thanks Spooky - I should have been more clear when giving the "Factoid" which I meant to be a nostalgic piece of coding history back from the "old school" days of basic, or at least what I know of them

-RUST-
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Oct 2003 00:12
Now in C++, to have a string variable you would create a char array.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Oct 2003 00:13
Oops, didn't mean that to be so abrupt
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Oct 2003 02:33
@IanM

-RUST-

Login to post a reply

Server time is: 2024-09-21 03:54:41
Your offset time is: 2024-09-21 03:54:41