04-30-2022, 05:25 AM
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.
Now, let's break down what we're doing here, line by line.
Our first line of code is:
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.
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?
Now this line gets a little tricky for some people, as they confuse it with the newest syntax for DIM. They think that the way it's written, all the variables on this line are _FLOAT. They're not! Just compare this line to the one above it, and then apply the same logic as the first DIM statement we looked at. What types are the three variables here?
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.
And here, we have the new syntax for how one can DIM variables. If you notice, the type comes first on the left, with all the variables of this explicit type to be to the right of the type definition. j, k, and l are all String type variables.
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.
Code: (Select All)
Dim a, b, c
Dim d As Integer, e As Double, f As Single
Dim g, h, i As _Float
Dim As String j, k, l
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.