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

Option Explicit not working...

Status
Not open for further replies.

Stoemp

Programmer
Sep 25, 2002
389
BE
As a former VB user I always used the 'option explicit' line to be sure all my variables are correct. This should work in asp, but it doesn't with my code... Is there any reason it would not work? I get the following error:

'The option explicit option is unknown or invalid'

This is the code I use at the top of my page:

<%
@LANGUAGE=&quot;VBScript&quot;

Option Explicit
%>
 
The language declaration needs to be in it's own line (along with transaction specifcation if needed)

try

<%@LANGUAGE=&quot;VBScript&quot; %>
<% Option Explicit

' Insert other code where required

%>
 
<% @LANGUAGE=&quot;VBScript&quot; %>
<% Option Explicit %>

seperate them Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Ok, didn't know that! Thank you for the lightspeed answer ;-)
 
Apparently I was too enthousiastic. It's still not working. I separated them, but now I get the error:

'Instruction expected'
bio2/food/include/header.asp, line 4
Option Explicit

I use asp and html in one page. Is this a problem?
 
could you post the first 5 or 6 lines from the page ?


it should read

<%@ Language=VBScript %>
<% Option Explicit %>
<HTML>
<HEAD>
</HEAD>
<BODY>
</BODY>
</HTML>

etc
 
These are the first lines of my page. It comes from a header file that is being included in all the pages

<!-- Start of include file: header.asp -->

<% @LANGUAGE=&quot;VBScript&quot; %>
<% Option Explicit %>

<%
DIM sLang

sLang = Request.Cookies(&quot;lang&quot;)

If ( sLang = &quot;&quot; ) Then

Response.Redirect(&quot;../index.asp&quot;)

End If

%>

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
 
I still get the same error :-(
Maybe I should drop the option explicit and try to be careful when using variables...
 
Try removeing the comment at the top of the file. Move everything else up to the top. I have a feeling the problem is because you are outputting to the buffer (even if it is an html comment) before declaring your language and option explicit.
As a second portion of this answer, you could be lazy and forego declaring the language. ASP defaults to VB so you could simply:
Code:
<% Option Explicit %>

<%
    DIM sLang
    
    sLang = Request.Cookies(&quot;lang&quot;)
    
    If ( sLang = &quot;&quot; ) Then
    
        Response.Redirect(&quot;../index.asp&quot;)

    End If

%>

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
...

If this is an include file than you don't want to put the option explicit in it. When the file is included, you can think of it as if it is creating one big long file with all of the include statements replaced by the contents of your include files. Than the script processes, so if you have an option explicit in your include files it throws an error because it is not at the top of the script.

Final result: Now that I have seen you are including this everywhere, delete the option explicit. As long as it is in the file including this one, it will evaluate this one the same way.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
I think I'll just drop the option explicit. When the comment is removed, the situation stays the same. In fact the lack of the 'option explicit' is not such a problem. It's just very useful for programming right. I'll double-check my code and variables. That'll work too I guess.

Thank you all for your help
 
The less confusing and more awake version of the above post: As long as the option explicit is in your code that is including everything else, it will function as if it is in the included code as well.

Hope that was bit clearer :p

-tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
In fact it's even more confusing :p

The header file I include is included at the very top of the document, so normally the top code in the header.asp document will be the top code in the parent document. That's why I don't get it why this doesn't work...
 
Don't you just have to put your header include after the language declaration statement?
 
I can try that. The fact is I want to use as many code as possible in the include files so I don't have to type all the code in all the pages. I'll certainly try to put the language declaration and option explicit before the include statement.

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top