Forum Moderators: open

Message Too Old, No Replies

DIM statement - required?

         

tesla

5:07 pm on Sep 29, 2002 (gmt 0)

10+ Year Member



If in my ASP code, I create a variable like:

Temp = Request("Data")

Do I need to add a DIM statement first?

DIM Temp
Temp = Request("Data")

It seems to work without it but perhaps I'm creating some larger issue overtime or with load such as an Internal Server Error?

And if I use the DIM statement will I need to later remove the variable with:

Set Temp = Nothing ?

Thanks,

txbakers

8:09 pm on Sep 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dim isn't required, but it's good practice to include it.

You might want to also include option explicit, which requires that you declare the variables that way.

If you don't declare the variables first, they will instantiate, but you run the risk of making errors with typoes. for instance, if you say:

temp = 16

and want to use that later, in a computation, you might type this:

timp = 18

and you'll have both variables out there.

saurabh

2:16 am on Sep 30, 2002 (gmt 0)

10+ Year Member



VBScript dosent require you to declare variables with a Dim statement before using them.

and you'll have both variables out there

To prevent such things from happening put a "option explicit" statement before any ASP code. This statement means that you have to explicitly declare variables with Dim before you can use them. So if you have declared "Dim temp" but later write timp=18, it gives you an error.

And if I use the DIM statement will I need to later remove the variable with:
Set Temp = Nothing?

No, you need to do this only for objects for which you have alotted memory previously with the "set" statement. Say,

set myobj=server.creatobject("blah.blah")

to free memory when you are done with it,

set myobj=nothing