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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

option explicit? need some info on it

Status
Not open for further replies.

terror

Programmer
Aug 22, 2001
86
US
Hiya,
I understand that option explicit is used to help in debugging, but I do not understand how. I think, if you use option explicit, you must declare all your variables in the beginning of your code, is this correct? I am having difficulty finding info on this, can someone tell me where to look?
also, when I attempt to use option explicit in my code online, the code works. But when I take that same asp page and use it in Ultradev with IIS, I get an error. If I take option explicit out, the code works. If you need my code, let me know.
thanks,
Terror
 
I don't know that much about UltraDev but I can tell you what I know about Option Explicit.
I use it when first developing my code. I make it the very first line of code <%Option Explicit%>. After that you cannot call a variable that has not been explicitly declared ie. Dim myVariable. This comes in handy to prevent typos from creeping up on you. Lets say I have a variable myVariable and later in the code I do something with it like myVariable = myVariable + 1. That is all fine. But say I did myVaraible = myVariable + 1. Option Explicit will catch this and tell me myVaraible has not been defined. If you do not use Option Explicit then it will just create a new variable called myVaraible and this can prove tricky and a bummer to catch sometimes. Once you are done developing you can go ahead and strip the Option Explicit out of the code because it is no longer needed and there is no need to make the server check all your variables once you know the code is correct. Anyway, that is my understanding of it.
I hope this helps. Sorry I don't know why UltraDev is causing problems but I have no experience with it.

The following is what MSDN says about it:

If used, the Option Explicit statement must appear in a script before any procedures.

When you use the Option Explicit statement, you must explicitly declare all variables using the Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable name, an error occurs.


--------------------------------------------------------------------------------

Tip Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear.


I hope this helps. Sorry I don't know why UltraDev is causing problems but I have no experience with it.
 
Hey Jitter,
thanks alot. You explained it perfectly for me. Ultrdev is a strange animal in some ways. You answered my real question though.
thankyou kindly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top