Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A bit dim about "DIM"
#1
I'm a bit confused, appropriately, about the DIM function.
I read that we can dim a whole range of vars, like a to z, as a group in one go, but I don't seem to be able to.
Is this implemented yet, or am I wrong again? Confused
Reply
#2
I think what you're looking for is DEFINT, DEFSGN, DEFLNG, DEFDBL & DEFSTR.

You can define a range of variables starting with certain characters AS a certain type variable, for example:
DEFSNG A - G

would define all variables starting with A thru G as singles. I believe it's a holdover from the days of limited memory and is mostly to maintain code compatibility. I never use it, myself.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#3
(04-30-2022, 03:34 AM)PhilOfPerth Wrote: I'm a bit confused, appropriately, about the DIM function.
I read that we can dim a whole range of vars, like a to z, as a group in one go, but I don't seem to be able to.
Is this implemented yet, or am I wrong again? Confused

Edit: I see OldMoses beat me to it...

You may be thinking of DEFINT (Define Interger)

DEFINT A-Z ' Makes every numerical variable an integer.

For the DIM statement, you may be thinking of a to z, but what is available is DIM for the number of elements, as in...

DIM count (1 to 1000)

or

DIM count(1 to 1000) AS INTEGER

or

a = 1: b = 10: DIM count(a TO b) AS STRING

DIM can also be used with TYPE statements.

Maybe to cut to the chase, what action are you trying to accomplish?

Pete
Reply
#4
I'm just trying to improve my coding, and reduce the size of the file by changing all my numeric vars to integer, then changing any that may need another type to that ,
as in (now that I have this info) DEFINT a to z: DEFDBL atoms. You both answered my question; thank you.
Reply
#5
Quote:Pete wrote: "DIM can also be used with TYPE statements."

I think Pete wanted to say this:

In older QB64 versions for typing of variables you have to use the DIM for every value like this :


Code: (Select All)
DIM A AS INTEGER
DIM B AS INTEGER
DIM C AS INTEGER
...
DIM X AS DOUBLE
DIM Y AS DOUBLE
DIM Z AS DOUBLE...

In the newer Versions (I don't know since which version number)  you can write:

Code: (Select All)
DIM A, B, C AS INTEGER
DIM X, Y, Z AS DOUBLE
Reply
#6
(04-30-2022, 04:56 AM)BSpinoza Wrote:
Quote:Pete wrote: "DIM can also be used with TYPE statements."

I think Pete wanted to say this:

In older QB64 versions for typing of variables you have to use the DIM for every value like this :


Code: (Select All)
DIM A AS INTEGER
DIM B AS INTEGER
DIM C AS INTEGER
...
DIM X AS DOUBLE
DIM Y AS DOUBLE
DIM Z AS DOUBLE...

In the newer Versions (I don't know since which version number)  you can write:

Code: (Select All)
DIM A, B, C AS INTEGER
DIM X, Y, Z AS DOUBLE

Oh yeah, that's certainly a possibility. I've only used the new method a couple of times. Very married to the old style, but the new method is definitely a time saver. Well any bases we haven't covered here, guys?

Pete
Reply
#7
Not quite.  It's:

Code: (Select All)
DIM AS DOUBLE A, B, C
DIM AS INTEGER X, Y, Z

DIM AS <TYPE> then the variable names.

Here, a quick little reference for the differences, written up and shared in our Learning Resources area. https://qb64phoenix.com/forum/showthread.php?tid=279

I hope that helps clear up any confusion anyone may have had with the new syntax. Wink
Reply
#8
(04-30-2022, 05:08 AM)SMcNeill Wrote: Not quite.  It's:

Code: (Select All)
DIM AS DOUBLE A, B, C
DIM AS INTEGER X, Y, Z

DIM AS <TYPE> then the variable names.

Here, a quick little reference for the differences, written up and shared in our Learning Resources area.  https://qb64phoenix.com/forum/showthread.php?tid=279

I hope that helps clear up any confusion anyone may have had with the new syntax.  Wink

It's quite right what you write, Steve,
but QB64 also accepts my version of DIM:

Code: (Select All)
'DIM test
OPTION _EXPLICIT

DIM a, b, c AS INTEGER
DIM x, y, z AS DOUBLE

a = 1: b = 1: c = 1
x = 1.234
y = 1.234
z = 1.234

PRINT a + b + c
PRINT x + y + z

QB64 compiles this without any problems!

... but only c is explicit declared as integer and only z as double... I understand.
Reply
#9
Then it seems that DIM AS DOUBLE A, B, C
DIM AS INTEGER X, Y, Z is the safer option, and given that they both take the same amount of typing, I'll stay with that. Thanks for clarifying.
(this was written before I read Steve's full explanation)
Reply




Users browsing this thread: 1 Guest(s)