wellwet
asked on
Dim in asp
Hi expert,
I just cannot see why we need to declare a variable:
Dim i
for i = ....
Can you explain?
I just cannot see why we need to declare a variable:
Dim i
for i = ....
Can you explain?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DIM this is keyword admired by most of the people that what is the usage and why we need to use. yes defenitly we need to use.
Suppose you are including a file which has a variable and assign some values to it namely Procedurs.asp. In this case unless you declare(DIM) that variable in main.asp, you cannot have the scope of that variable in main.asp. This is the main reason why we need to use DIM. see the example..,
procedures.asp
----------------
strUser = "wellwet"
main.asp
-----------
<% DIM strUser 'to get scope of variable at Procedures.asp%>
<!--#include File="Procedures.asp"-->
<% Response.write "User = "& strUser %>
Note:
1. Its a must to declare the variable before including the file.
2. If you declare strUser both in .asp files you will get error.
The main thing is DIM deals with the SCOPE of a varaible,object, etc.,
You can also do the same by declaring an object and get the scope in another file using "include".
Having this code you can feel how it DIM works.
thanks,
mani.v
Suppose you are including a file which has a variable and assign some values to it namely Procedurs.asp. In this case unless you declare(DIM) that variable in main.asp, you cannot have the scope of that variable in main.asp. This is the main reason why we need to use DIM. see the example..,
procedures.asp
----------------
strUser = "wellwet"
main.asp
-----------
<% DIM strUser 'to get scope of variable at Procedures.asp%>
<!--#include File="Procedures.asp"-->
<% Response.write "User = "& strUser %>
Note:
1. Its a must to declare the variable before including the file.
2. If you declare strUser both in .asp files you will get error.
The main thing is DIM deals with the SCOPE of a varaible,object, etc.,
You can also do the same by declaring an object and get the scope in another file using "include".
Having this code you can feel how it DIM works.
thanks,
mani.v
ASKER
Thank you for all experts who helped me in this question.
please read this article for a good explanation of WHY option explicit should always be used...
http://www.4guysfromrolla.com/webtech/faq/Intermediate/faq6.shtml
BRUNO