A bit dim about "DIM" - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: A bit dim about "DIM" (/showthread.php?tid=278) |
A bit dim about "DIM" - PhilOfPerth - 04-30-2022 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? RE: A bit dim about "DIM" - OldMoses - 04-30-2022 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. RE: A bit dim about "DIM" - Pete - 04-30-2022 (04-30-2022, 03:34 AM)PhilOfPerth Wrote: I'm a bit confused, appropriately, about the DIM function. 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 RE: A bit dim about "DIM" - PhilOfPerth - 04-30-2022 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. RE: A bit dim about "DIM" - BSpinoza - 04-30-2022 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 In the newer Versions (I don't know since which version number) you can write: Code: (Select All) DIM A, B, C AS INTEGER RE: A bit dim about "DIM" - Pete - 04-30-2022 (04-30-2022, 04:56 AM)BSpinoza Wrote:Quote:Pete wrote: "DIM can also be used with TYPE statements." 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 RE: A bit dim about "DIM" - SMcNeill - 04-30-2022 Not quite. It's: Code: (Select All) DIM AS DOUBLE A, B, C 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. RE: A bit dim about "DIM" - BSpinoza - 04-30-2022 (04-30-2022, 05:08 AM)SMcNeill Wrote: Not quite. It's: It's quite right what you write, Steve, but QB64 also accepts my version of DIM: Code: (Select All) 'DIM test QB64 compiles this without any problems! ... but only c is explicit declared as integer and only z as double... I understand. RE: A bit dim about "DIM" - PhilOfPerth - 04-30-2022 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) |