How is variables declared in VBScript?

Questions by Bessie   answers by Bessie

Showing Answers 1 - 5 of 5 Answers

lata

  • Jul 31st, 2007
 

You can declare variables with the Dim, Public or the Private statement. Like this: 

dim name name=some value

Declaring variables in VB is optional, even if you don't declare any variable, it hardly matters.

But if you want to declare, just use Dim or Redim (if you are using dynamic array)

for Example :

Dim myVariable
Dim myName
Dim myArray(10)
ReDim myArray (50)

  Was this answer useful?  Yes

Shaistha Anjum

  • Sep 22nd, 2011
 

There are two type of variable declaration:

1)Implicit: Here we need not declare any variable. Explicitly vbs declare all such variable on behalf of us

2)Explicit: Here we declare variable using DIM keyword. Dim a,d,c

  Was this answer useful?  Yes

shamimamd

  • Sep 26th, 2011
 

Declare a variable, a constant

Dim [Const] $variable [ = initializer ]
Dim [Const]

You can also declare multiple variables on a single line:
Dim $a, $b, $c

And initialize the variables:
Dim $a = 2, $b = 10, $c = 20


Creating constants can be done in a similar way:
Const $a = 2, $b = 10, $c = 20
Dim Const $d = 21, $e = Exp(1)
Local Const $f = 5, $g = 7, $h = -2

Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!)
Global = Forces creation of the variable in the Global scope
Local = Forces creation of the variable in the Local/Function scope

  Was this answer useful?  Yes

shamimamd

  • Sep 28th, 2011
 

Simple way -

Dim L, W --------------------(L and W is a variable)

L = 3
W = 5

(so now your L value is 3 and W value is 5)

Area = L*W

Please Bessie tell me what would be the expected result out of it

Area = ?
-----------------------------
Result
Area = 15





Declare a variable, a constant

Dim [Const] $variable [ = initializer ]
Dim [Const]

You can also declare multiple variables on a single line:
Dim $a, $b, $c

And initialize the variables:
Dim $a = 2, $b = 10, $c = 20


Creating constants can be done in a similar way:
Const $a = 2, $b = 10, $c = 20
Dim Const $d = 21, $e = Exp(1)
Local Const $f = 5, $g = 7, $h = -2

Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!)
Global = Forces creation of the variable in the Global scope
Local = Forces creation of the variable in the Local/Function scope

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions