Difference between revisions of "Dim"

From NSB App Studio
Jump to navigation Jump to search
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
DIM ''nameA''[([''subscriptA'' [,''subscriptB'' [,''subscriptC''...]]])]<br />              [, ''nameB''...[, ''nameC''..., [...]]]
+
Dim ''nameA''[([''subscriptA'' [,''subscriptB'' [,''subscriptC''...]]])][, ''nameB''...[, ''nameC''..., [...]]]
  
'''Description'''
+
Dim  ''nameA'' = ''simplevariable''
  
DIM is used to declare variables and allocate storage space. The required component, nameA, is the name of the variable, it must follow standard variable naming conventions. The optional list of subscripts are the upper bounds of dimensions of an array variable. Up to 60 comma-separated dimensions may be declared. Script level variables are available to all procedures in the script; procedure level variables are available only in the procedure they are declared in. The lower bound of an array is always zero.
+
== Description ==
  
'''Example'''
+
Dim is used to declare variables and allocate storage space. The required component, nameA, is the name of the variable, it must follow standard variable naming conventions. The optional list of subscripts are the upper bounds of dimensions of an array variable. Up to 60 comma-separated dimensions may be declared. The lower bound of an array is always zero.
  
<pre>
+
An optional initial value can also be supplied. This must be a simple variable, not an expression.
REM DIM Example
+
 
'DIM declares variables and allocatesstorage
+
Arrays must be declared in a Dim statement. Arrays should have a Dim statement in each Code Module where they are used. For multidimensional arrays, A(2,3) refers to the same element as A[2][3].
 +
 
 +
=== Scope ===
 +
Variables which are declared outside of any Function or Sub are global and are available everywhere in your code, even on other forms. Variables which are declared inside a Function or Sub are only available while the routine is being executed and are lost when the routine is ended. Variables which are used without being declared are global.
 +
 
 +
== Example ==
 +
 
 +
<tabber>
 +
JavaScript=
 +
<syntaxhighlight lang="JavaScript">
 +
// Var Example
 +
/* Var declares variables and allocates storage */
 +
 
 +
//An empty variable named "Foo"
 +
var Foo;
 +
//A variable with an initial value of 42
 +
var Foo2 = 42;
 +
//A one-dimensional array with 10 elements
 +
var OneD = new Array(9);
 +
//A two-dimensional array with 600 elements
 +
//20 x 30
 +
var TwoD = new Array(19, 29);
 +
</syntaxhighlight>
 +
|-|
 +
BASIC=
 +
<syntaxhighlight lang="vb.net">
 +
Rem Dim Example
 +
'Dim declares variables and allocates storage
 
'An empty variable named "Foo"
 
'An empty variable named "Foo"
DIM Foo
+
Dim Foo
 +
'A variable with an initial value of 42
 +
Dim Foo2 = 42
 
'A one-dimensional array with 10 elements
 
'A one-dimensional array with 10 elements
DIM OneD(9)
+
Dim OneD(9)
 
'A two-dimensional array with 600 elements
 
'A two-dimensional array with 600 elements
 
'20 x 30
 
'20 x 30
DIM TwoD(19, 29)
+
Dim TwoD(19, 29)
</pre>
+
</syntaxhighlight>
 +
</tabber>
 +
 
 +
== Related Items ==
 +
 
 +
[[array|Array]], [[redim|ReDim]], [[set|Set]]
  
'''Related Items'''
+
[[Category:Language Reference]]
  
[[array|ARRAY]], [[redim|REDIM]], [[set|SET]]
+
[[Category:Variables]]

Latest revision as of 14:08, 24 July 2019

Dim nameA[([subscriptA [,subscriptB [,subscriptC...]]])][, nameB...[, nameC..., [...]]]

Dim nameA = simplevariable

Description

Dim is used to declare variables and allocate storage space. The required component, nameA, is the name of the variable, it must follow standard variable naming conventions. The optional list of subscripts are the upper bounds of dimensions of an array variable. Up to 60 comma-separated dimensions may be declared. The lower bound of an array is always zero.

An optional initial value can also be supplied. This must be a simple variable, not an expression.

Arrays must be declared in a Dim statement. Arrays should have a Dim statement in each Code Module where they are used. For multidimensional arrays, A(2,3) refers to the same element as A[2][3].

Scope

Variables which are declared outside of any Function or Sub are global and are available everywhere in your code, even on other forms. Variables which are declared inside a Function or Sub are only available while the routine is being executed and are lost when the routine is ended. Variables which are used without being declared are global.

Example

// Var Example
/* Var declares variables and allocates storage */

//An empty variable named "Foo"
var Foo;
//A variable with an initial value of 42
var Foo2 = 42;
//A one-dimensional array with 10 elements
var OneD = new Array(9);
//A two-dimensional array with 600 elements
//20 x 30
var TwoD = new Array(19, 29);

Rem Dim Example
'Dim declares variables and allocates storage
'An empty variable named "Foo"
Dim Foo
'A variable with an initial value of 42
Dim Foo2 = 42
'A one-dimensional array with 10 elements
Dim OneD(9)
'A two-dimensional array with 600 elements
'20 x 30
Dim TwoD(19, 29)

Related Items

Array, ReDim, Set