Declaring variables

What is the difference if we use Dim to declare a variable and one without declaring it.

Questions by mabobine   answers by mabobine

Showing Answers 1 - 6 of 6 Answers

akothuru

  • Jul 29th, 2008
 

"Dim" keyword is related to VB Script. There is no difference if you do not declare the variables with/with out declaration where your script does not have the statement "Option Explicit"

"Option Explicit" is keyword which can be used in VB Script to declare a variable. If you specify Option Explicit in you script, what ever the variable you are using in your script should be declared before accessing it. Otherwise it gives the syntax error so that you can't execute the script at all. So here, you should use "Dim" keyword to declare varialbes.

Using Dim, user can declare variables. When you declare a variable, it acts as Variant. No memory is allocated in RAM for that variable at the time of declaration. Based on the value assign to it, that bytes of memory will be allocated to this variable at run time.

1. Actually while declaring variables' there is no difference between, with using dim and without using dim
2. But it is better to use dim and option explicit
3. If we option explicit then we should declare variables using dim, otherwise it will throw an error.

Below I will give 2 small examples
abcd=20
msgbox acbd
o/p: empty prompt box

option explicit
dim abcd=20
msgbox acbd
o/p: some error prompt

so that
you can get to know where is the problem

  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