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!

Name Redefined error

Status
Not open for further replies.

Faheemi

Programmer
Sep 2, 2001
59
HK
Hi there,

I got the ASP code as follows:

file1.asp
*****************************************************
<%
If a = 10 then
%>
<!--#include file=&quot;general.asp&quot;-->
and do something
<%
ElseIf a =20 then
%>
<!--#include file=&quot;general.asp&quot;-->
and do something
<%
Else
<!--#include file=&quot;general.asp&quot;-->
and do something
<%
End If
%>

*************************************

general.asp
***********************************
<%
Dim a,b
Response.Write(a)
.
.
and so on...
%>
***********************************

When I tried to run this file1.asp I got the following error:

Microsoft VBScript compilation (0x800A0411)
Name redefined


I understand that this error occurs when you tried to do
Dim for the same variable more than once. I do include the file two to three times in the file1.asp. But you can see that I include it on a conditional basis. So it is included only once and there is no possibility of getting this error.

But I still get the error. So please help me solve the problem.

Thank you very much.

Faheem Hameed
 
You need to look at the file name and the line position that the error is pointing to. Can you post that here ?

ToddWW
 
make sure you do not have a variable name in the include file with the same name as a variable on the page that you are including that file on.
 
The include files are loaded prior to the server-side scripts processing. Therefore, the include file is loaded three times in your example, hence a,b are defined three times.
Best solution is to define your variables in the calling script, not the included files, ie:

file1.asp
*****************************************************
<%
Dim a,b

If a = 10 then
%>
<!--#include file=&quot;general.asp&quot;-->
and do something
<%
......


general.asp
***********************************
<%
Response.Write(a)
 
Faheem,

I just realized that you don't have <% Option Explicit %> at the top of your file1.asp page. Because of that, your first line IF a = 10 then is dimming that variable a. Then, of course, your include file is trying to re-dim it.

I would highly recommend that you use Option Explicit. It requires you to dim all of your variables and helps when troubleshooting problems like this. I have the following at the top of every ASP page in my App.
Code:
<%@ Language=VBScript %>
<% Option Explicit %>

Also, I dim all of my variables at the top of my pages. That way, I only have one place to go to see all of that. To fix your problem, without doing anything else, remove the Dim a,b from your include files.

ToddWW
 
Thanks for all of your input. I used all the Dim statements in the calling file which solved my problems.

Also instead of #include I tried to use Server.Execute statement which was too worked for me. But the problem with Server.Execute is, if I assign a variable in the CALLED file it is not available to the CALLING file. Otherwise the Server.Execute is a great alternative to server side includes.

Hameed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top