Server-side includes (IIS 5, classic VBScript)

M

MyndPhlyp

I am building up a library of Class'es that represent various columns of
table layouts. One often used column is "name" and each occurrence is
treated identically. (What a concept, eh?)

Part of that library of Class'es includes representations of various tables.
(Just let me know if you see a trend going on here.) These Class'es use the
column Class'es.

What I would like to do, but I have yet to find a way around duplicated
names, is to place all the necessary supporting column Class #include's in
the table's Class so that I need only place the table's Class in the module
utilizing them.

I understand entirely why the "duplicate name" error occurs.

What I am looking for is a way around the conundrum that does not require
duplication of code. Any ideas?
 
R

Ray Costanzo [MVP]

I didn't fully follow your explanation here, but try declaring your
variables in a narrower scope in your classes. Don't just dim everything
out in the open. Encapsulate logic into subroutines and functions, and use
local variables within them.

Ray at work
 
M

MyndPhlyp

Ray Costanzo said:
I didn't fully follow your explanation here, but try declaring your
variables in a narrower scope in your classes. Don't just dim everything
out in the open. Encapsulate logic into subroutines and functions, and use
local variables within them.

Thanks Ray, but I'm already doing that.

Just to be a bit more specific about the problem, the "duplicate name"
errors refer to the Class names.

Consider this scenario ...

One record layout describes a Company. The Company record has a column
(Property) called Name among other things.

Another record layout describes a Person. The Person record has columns
(Properties) called FName, MName, and LName.

All 4 name fields are of a Class clName.

The Class library looks something like:

Class clCompany
(uses clName for 1 property)

Class clPerson
(uses clName for 3 properties)

In the ASP using the Company and Person Class'es I am forced to do something
like:

(Main ASP file)
<#include file="clName.asp">
<#include file="clCompany.asp">
<#include file="clPerson.asp">

What I would rather do is pull the column #include out of the main ASP and
instead place it in the Class'es that require it. That would leave me with
something like this:

(Main ASP file)
<#include file="clCompany.asp">
<#include file="clPerson.asp">

(clCompany Class file)
<#include file="clName.asp">

(clPerson Class file)
<#include file="clName.asp">

But that will cause a VBScript error because the Class name in "clName.asp"
is redefined (duplicated).

Is there a way to gracefully get around this?
 
P

Patrice

AFAIK no as includes are processed even before ASP gets in play. I would
just keep the first design.

More specifically my personal preference in ASP was to do something like :
- to have my main file (ASP page)
- this main file includes a "coordination file"
- this "coordination file" includes in turns all other needed files
- eventually I could create another "coordination file" to include less
files if the number is growing and I really use much less than included

Finally it could give something like :
include virtual="/include/all.asp" in my main file

<#include file="clName.asp">
<#include file="clCompany.asp">
<#include file="clPerson.asp">
in "all.asp" for a start...
 
M

MyndPhlyp

Patrice said:
AFAIK no as includes are processed even before ASP gets in play. I would
just keep the first design.

More specifically my personal preference in ASP was to do something like :
- to have my main file (ASP page)
- this main file includes a "coordination file"
- this "coordination file" includes in turns all other needed files
- eventually I could create another "coordination file" to include less
files if the number is growing and I really use much less than included

Finally it could give something like :
include virtual="/include/all.asp" in my main file

<#include file="clName.asp">
<#include file="clCompany.asp">
<#include file="clPerson.asp">
in "all.asp" for a start...

I started going down that path - including all the classes in a common ASP
and then including the common ASP into the true ASP - but started
considering the amount of overhead involved in loading up all the extraneous
code.

Google'ing around, this subject seems to be an unresolved problem with
respect to classes and I may have to continue down the original path of
including all the record layout and column definition Class'es in each ASP.

If I could define a Class within a Class it would solve the problem because
I could "temporarily" escape out of the record's Class (%>) to fire off the
#include for the column's generic Class and then unescape back into the
script (<%). That would allow the column Class'es to be unique to the
record's Class.

I guess I am just pushing the envelope a tad bit too far.
 
P

Patrice

Yes includes lacks for example some preprocessing capabilities.

I would just create here an alternate to the "all" file that includes only a
subset of the modules hat is enough for several pages. Also try perhaps to
see if this really causes a problem to see if it's worth...

Another approach could be perhaps to keep a single list (ie. you include all
you need in each page from a "model" list with dependencies comments) and
you just "comment" the parts you don't need...

Solved in ASP.NET ;-)
 
M

MyndPhlyp

Patrice said:
Yes includes lacks for example some preprocessing capabilities.

I would just create here an alternate to the "all" file that includes only a
subset of the modules hat is enough for several pages. Also try perhaps to
see if this really causes a problem to see if it's worth...

Another approach could be perhaps to keep a single list (ie. you include all
you need in each page from a "model" list with dependencies comments) and
you just "comment" the parts you don't need...

Solved in ASP.NET ;-)

Ah, but the rules say we must play the cards we were dealt. ASP.NET violates
the rules in this rather warped game. I have already resigned myself to
listing all the needed Class'es in each main ASP and documented the required
#include's at the beginning of each record layout Class. It simplifies thing
just a bit but still lacks grace.

Another nice approach, if IIS and VBScript were structured just a little
different, would have been to "include" all the Class'es once in something
like a Global.asa (actually, a more suitable library of sorts) and then be
able to utilize those Class'es simply by reference in the rest of the
application. Of course, if that were possible, I would also want my GDE to
be aware of those add-on Class'es and provide me with hints (and error
alerts) as the code gets developed maybe even going as far as something
Borland did with their Java GDE. (It would also provide the comments in the
hint if function-level comments existed.)

The dreaming eventually ends and we return to our regularly scheduled
nightmare.

Thanks for sharing your ideas though. Maybe I will be fortunate enough to
dig into ASP.NET before it becomes obsolete ... or maybe I will just wait it
out until the next new thing.
 
C

Chris Hohmann

MyndPhlyp said:
I am building up a library of Class'es that represent various columns of
table layouts. One often used column is "name" and each occurrence is
treated identically. (What a concept, eh?)

Part of that library of Class'es includes representations of various
tables.
(Just let me know if you see a trend going on here.) These Class'es use
the
column Class'es.

What I would like to do, but I have yet to find a way around duplicated
names, is to place all the necessary supporting column Class #include's in
the table's Class so that I need only place the table's Class in the
module
utilizing them.

I understand entirely why the "duplicate name" error occurs.

What I am looking for is a way around the conundrum that does not require
duplication of code. Any ideas?

You could do it with JScript. Here's a proof of concept that demonstrates
redeclaration of the clName class/object:

<script language="JavaScript" runat="SERVER">
function clName(sName){
this.Value = sName;
}

function clCompany(sName){
this.Name = new clName(sName);
}

function clName(sName){
this.Value = sName;
}

function clPerson(sLastName, sFirstName, sMiddleName){
this.LastName = new clName(sLastName);
this.FirstName = new clName(sFirstName);
this.MiddleName = new clName(sMiddleName);
}

var company = new clCompany("Hohmann Enterprises");
var person = new clPerson("Hohmann", "Chris", "George");
Response.Write("<br>Company: " + company.Name.Value);
Response.Write("<br>Person: " + person.LastName.Value + ", " +
person.FirstName.Value + " " + person.MiddleName.Value);
</script>


Notes:
1. You can still use VBScript for the rest of your programming, only your
classes would need to be written in JScript.
2. JScript also supports a much more robust object implementation which
includes functions-as-values, reflection, prototyping, nesting, etc...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top