Difference between revisions of "Dim"

From NSB App Studio
Jump to navigation Jump to search
(Add javascript snippet)
Line 9: Line 9:
 
An optional initial value can also be supplied. This must be a simple variable, not an expression.
 
An optional initial value can also be supplied. This must be a simple variable, not an expression.
  
== Example ==
+
== Example (Basic) ==
  
 
<pre>
 
<pre>
 
Rem Dim Example
 
Rem Dim Example
'Dim declares variables and allocatesstorage
+
'Dim declares variables and allocates storage
 
'An empty variable named "Foo"
 
'An empty variable named "Foo"
 
Dim Foo
 
Dim Foo
Line 23: Line 23:
 
'20 x 30
 
'20 x 30
 
Dim TwoD(19, 29)
 
Dim TwoD(19, 29)
 +
</pre>
 +
 +
== Example (JavaScript) ==
 +
<pre>
 +
// 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);
 
</pre>
 
</pre>
  

Revision as of 16:25, 19 May 2013

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. 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.

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

Example (Basic)

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)

Example (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);

Related Items

Array, ReDim, Set