Posts: 653
Threads: 96
Joined: Apr 2022
Reputation:
22
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?
Posts: 276
Threads: 14
Joined: Apr 2022
Reputation:
27
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:
Posts: 2,183
Threads: 222
Joined: Apr 2022
Reputation:
104
04-30-2022, 03:56 AM
(This post was last modified: 04-30-2022, 03:57 AM by Pete.)
(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?
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
Posts: 653
Threads: 96
Joined: Apr 2022
Reputation:
22
04-30-2022, 04:16 AM
(This post was last modified: 04-30-2022, 04:17 AM by PhilOfPerth.)
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.
Posts: 46
Threads: 7
Joined: Apr 2022
Reputation:
2
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
Posts: 2,183
Threads: 222
Joined: Apr 2022
Reputation:
104
(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
Posts: 2,698
Threads: 328
Joined: Apr 2022
Reputation:
217
04-30-2022, 05:08 AM
(This post was last modified: 04-30-2022, 05:26 AM by SMcNeill.)
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.
Posts: 46
Threads: 7
Joined: Apr 2022
Reputation:
2
04-30-2022, 06:10 AM
(This post was last modified: 04-30-2022, 06:56 AM by BSpinoza.)
(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.
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.
Posts: 653
Threads: 96
Joined: Apr 2022
Reputation:
22
04-30-2022, 10:16 AM
(This post was last modified: 04-30-2022, 10:27 AM by PhilOfPerth.)
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)
|