Steve's Quick Lesson on DIM - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Official Links (https://staging.qb64phoenix.com/forumdisplay.php?fid=16) +--- Forum: Learning Resources and Archives (https://staging.qb64phoenix.com/forumdisplay.php?fid=13) +--- Thread: Steve's Quick Lesson on DIM (/showthread.php?tid=279) |
Steve's Quick Lesson on DIM - SMcNeill - 04-30-2022 Let's talk about DIM for a moment! To help us have this conversation, let's refer to the following code, which you can compile and stare at in your IDE if you want, just to test and make certain that the syntax is, indeed, correct. Code: (Select All) Dim a, b, c Now, let's break down what we're doing here, line by line. Our first line of code is: Code: (Select All) Dim a, b, c This is the simplest type of DIM statement, and it simply says that we're going to officially DIM and name three variables to whatever the default type is. Without any DEF or _DEFINE statement, these three variables are all going to be the default type of SINGLE. Code: (Select All) Dim d As Integer, e As Double, f As Single Here, we're assigning a set type of each variable in that single DIM statement. d is an integer. e is a double. f is single. Easy enough to follow along with the logic behind this statement, right? Code: (Select All) Dim g, h, i As _Float g is implicitly defined to be our default variable type -- SINGLE, in this case. So is h. i, on the other hand, is explicitly defined by the user to be a _Float. Code: (Select All) Dim As String j, k, l See the difference in the 3rd and 4th lines' syntax, and understand why they're two completely different things? If you want to define a large number of variables as a single type all at once, use the DIM AS <TYPE> syntax. Anything else would be incorrect. RE: Steve's Quick Lesson on DIM - PhilOfPerth - 04-30-2022 Great explanation Steve. I still had worries about this being the correct way for the multiple DIMing of vars, but now I get it. Thanks RE: Steve's Quick Lesson on DIM - admin - 05-01-2022 Wiki page updated back to where this information is now in it properly. https://qb64phoenix.com/qb64wiki/index.php/DIM |