Monday, April 12, 2010

VB Scripting - Variables - Implicit Declaration

Previous12345678910Next

Implicit Declaration:


Implicit Declaration is a default declaration type in VB and there is no need for us to declare a variable before assigning a value to the variable. The declaration and definition happens in one step.


Implicit declaration is easy to use. We don’t need to keep track of the variables used in the VB script.

Example

Int1 = 28
Int2 = 30
Prod = Int1 * Int2
Msgbox Prod

Let’s see how this is stored in the memory.








From the above example Int1 and Int2 are operands and the * is the operator and = is the assignment operator. Int1, Int2, Prod are Implicit Variables and as the script is executed in the memory the variables get created in the memory and the respective values are stored in those locations. With this type of declaration it is easy to create variables as and when required.

The one disadvantage of Implicit variables is that if there is a typo error in any line like for example "Prod" is mistyped as "Prd" then when the scrip is executed it creates another variable called "Prd" and the resultant out put is null (Nothing will be displayed). We should be careful in using the Implicit Declarations.

Previous12345678910Next

No comments:

Post a Comment