Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between "Set" and "Dim"? 2

Status
Not open for further replies.

mirty12

Technical User
Jun 6, 2002
20
US
This may be a dumb question -- Would someone explain why in some cases a script uses DIM to set up variables, and in other cases a script will not have any DIM statements, but will use SET instead. Are these interchangeable? Is one preferred? Thanks!
 
Set "sets" a variable
Dim reserves space for one

With Set you would say: Set Name = "John"
Then Name will be John

With Dim: Dim Name
This way you can use "Name" later and give it a value then. Like:

Name = rs.Fields("Name").value Rob
Just my $.02.
 
Dim Statement

Declares variables and allocates storage space.

Set Statement

Assigns an object reference to a variable or property, or associates a procedure reference with an event.


Right out of the documentation.

Scripts without Dim statements that declare each variable have omitted the declaration Option Explicit near the head of the script. Leaving out Option Explicit is considered bad form, since it can lead to many hard-to-debug errors caused by simple typos.

Why not download the MS reference material? I'd be lost without it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top