If Option Explicit is on the default , the compiler requires a declaration for every variable you use. For more information, see Option Explicit Statement.
You can assign a value to a variable when it is created. For a value type, you use an initializer to supply an expression to be assigned to the variable. The expression must evaluate to a constant that can be calculated at compile time.
If an initializer is specified and a data type is not specified in an As clause, type inference is used to infer the data type from the initializer. In the following example, both num1 and num2 are strongly typed as integers.
In the second declaration, type inference infers the type from the value 3. Type inference applies at the procedure level. It does not apply outside a procedure in a class, structure, module, or interface.
For information about what happens when a data type or initializer is not specified, see Default Data Types and Values later in this topic.
You can use an object initializer to declare instances of named and anonymous types. The following code creates an instance of a Student class and uses an object initializer to initialize properties. You can declare several variables in one declaration statement, specifying the variable name for each one, and following each array name with parentheses. Multiple variables are separated by commas. If you declare more than one variable with one As clause, you cannot supply an initializer for that group of variables.
You can specify different data types for different variables by using a separate As clause for each variable you declare. Each variable takes the data type specified in the first As clause encountered after its variablename part. You can declare a variable to hold an array , which can hold multiple values. To specify that a variable holds an array, follow its variablename immediately with parentheses.
For more information about arrays, see Arrays. You can specify the lower and upper bound of each dimension of an array. To do this, include a boundslist inside the parentheses. For each dimension, the boundslist specifies the upper bound and optionally the lower bound. The lower bound is always zero, whether you specify it or not. Each index can vary from zero through its upper bound value.
The following two statements are equivalent. Each statement declares an array of 21 Integer elements. When you access the array, the index can vary from 0 through The following statement declares a two-dimensional array of type Double. Note that an upper bound represents the highest possible value for the index, not the length of the dimension. The length of the dimension is the upper bound plus one.
You can leave all the bounds blank in an array declaration. If you do this, the array has the number of dimensions you specify, but it is uninitialized.
It has a value of Nothing until you initialize at least some of its elements. The Dim statement must specify bounds either for all dimensions or for no dimensions. If the array has more than one dimension, you must include commas between the parentheses to indicate the number of dimensions. You can declare a zero-length array by declaring one of the array's dimensions to be A variable that holds a zero-length array does not have the value Nothing.
Zero-length arrays are required by certain common language runtime functions. If you try to access such an array, a runtime exception occurs. Hi Guys! This Panasonic guy may have an attitude but he really need to know what is the meaning of "Dim" and seems noone is able to tell him? Panasonic guy.. Dim" is an abreviation of "Dimension" if that what you want to know. The meaning of it has been described by one of our colleague here, to locate a strorage space in memory.
So, has everybody learned the new term by now? December 12th, , AM 7. Dim is short for Dimension. In Visual Basic it's how variables are declared.
The word Public means the variable or procedure is accessible by the whole program global. As string means the variable is of the string data type. A string is really just another name for text. You will come across other data types as well like integer and boolean.
Quick Navigation Visual Basic 6. NET Framework. How hard would it really be to port to Windows 8? Later on it came to be used to declare all kinds of variables, when the possibility to specify the type for variables was added in more recent implementations. Dimension a variable, basically you are telling the compiler that you are going to need a variable of this type at some point. Variable declaration. Initially, it was short for "dimension", which is not a term that is used in programming outside of this specific keyword to any significant degree.
Back in the day DIM reserved memory for the array and when memory was limited you had to be careful how you used it. Short for Dimension. It's a type of variable. You declare or "tell" Visual Basic that you are setting up a variable with this word.
For reference type, we have to use new keyword to create the new instance of the class or structure. Dim lblTop As New System. Dim statement can be used with out a datatype when you set Option Infer to On.
In that case the compiler infers the data type of a variable from the type of its initialization expression. Example :. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. Asked 12 years, 4 months ago.
Active 5 months ago. Viewed k times. What does Dim stand for in Visual Basic? Improve this question. Software Engineer Nick Katsivelos Nick Katsivelos 4, 4 4 gold badges 18 18 silver badges 11 11 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. In early releases of basic the only variables that needed to be declared were arrays. The "Dim" keyword was used to set the dimensions of this array.
I remember reading a gw-basic programming guide in the early 80's and I explicitly remember it explaining DIM meaning Declare In Memory.
0コメント