Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Application objects

0 views
Skip to first unread message

Carlos Felipe França da Fonseca

unread,
Jul 5, 2008, 5:02:54 AM7/5/08
to
My global.asa initiates the following application object:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
Application("TranslateDomain") = "MSFT.com"
End Sub

A different file from the same website uses JavaScript and needs to call
that application object TranslateDomain.
How is the syntax to call that application object in Javascript?

Thanks!!!

Felipe


Joe Fawcett

unread,
Jul 5, 2008, 5:43:29 AM7/5/08
to
The Application object has a collection, Contents, which is what you are
accessing via Application("TranslateDomain") .
So I think in JScript you would use Application["TranslateDomain"] or
Application.Contents("TranslateDomain")
Should be easy enough to set up a one page asp web site and try a few
variations.

That's assuming that when you were talking about server-side script. If you
meant how to retrieve the value client-side then you'll need something like:
<script type="text/javascript">
var sTranslateDomain = "<% = Application("TranslateDomain") %>";
</script>


--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

"Carlos Felipe França da Fonseca" <carlosfel...@gmail.com> wrote in
message news:#sYGr3n3...@TK2MSFTNGP05.phx.gbl...

Evertjan.

unread,
Jul 5, 2008, 6:03:20 AM7/5/08
to
Joe Fawcett wrote on 05 jul 2008 in microsoft.public.scripting.jscript:

> The Application object has a collection, Contents, which is what you are
> accessing via Application("TranslateDomain") .
> So I think in JScript you would use Application["TranslateDomain"] or
> Application.Contents("TranslateDomain")
> Should be easy enough to set up a one page asp web site and try a few
> variations.

Repeatingly run:

============= test.asp =============

<script language='javascript' runat='server'>

Response.write(Application('test'));
Application('test') = Application('test') + 'a';

</script>

====================================

Application.Contents and Application.contents give an error.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Carlos Felipe França da Fonseca

unread,
Jul 5, 2008, 5:59:49 PM7/5/08
to
Evertjan,

Do I need to use simple quotes or double quotes?

Tks,

Felipe

"Evertjan." <exjxw.ha...@interxnl.net> wrote in message
news:Xns9AD27A9A...@194.109.133.242...

Anthony Jones

unread,
Jul 6, 2008, 3:23:51 AM7/6/08
to
"Evertjan." <exjxw.ha...@interxnl.net> wrote in message
news:Xns9AD27A9A...@194.109.133.242...
> Joe Fawcett wrote on 05 jul 2008 in microsoft.public.scripting.jscript:
>
> > The Application object has a collection, Contents, which is what you are
> > accessing via Application("TranslateDomain") .
> > So I think in JScript you would use Application["TranslateDomain"] or
> > Application.Contents("TranslateDomain")
> > Should be easy enough to set up a one page asp web site and try a few
> > variations.
>
> Repeatingly run:
>
> ============= test.asp =============
>
> <script language='javascript' runat='server'>
>
> Response.write(Application('test'));
> Application('test') = Application('test') + 'a';
>
> </script>
>
> ====================================
>
> Application.Contents and Application.contents give an error.


What error do you get? Works fine for me.

--
Anthony Jones - MVP ASP/ASP.NET


Anthony Jones

unread,
Jul 6, 2008, 3:25:12 AM7/6/08
to
"Carlos Felipe França da Fonseca" <carlosfel...@gmail.com> wrote in
message news:OM38zpu3...@TK2MSFTNGP02.phx.gbl...

> Evertjan,
>
> Do I need to use simple quotes or double quotes?
>


You can enclose a string either like this 'a string' or like this "another
string" in javascript. IOW it doesn't matter you use either.

Evertjan.

unread,
Jul 6, 2008, 11:13:26 AM7/6/08
to
Anthony Jones wrote on 06 jul 2008 in
microsoft.public.scripting.jscript:

Same here.

Prehaps I made a spelling mistake.

Carlos Felipe França da Fonseca

unread,
Jul 6, 2008, 7:15:05 PM7/6/08
to
Hang on guys...

What's the syntax for Application.Contents?

Application["TranslateDomain"]
or
Application.Contents("TranslateDomain")

or
Application.Contents["TranslateDomain"]

Thanks,

Felipe

"Evertjan." <exjxw.ha...@interxnl.net> wrote in message

news:Xns9AD3AF2D...@194.109.133.242...

Joe Fawcett

unread,
Jul 7, 2008, 3:00:09 AM7/7/08
to
"Carlos Felipe França da Fonseca" <carlosfel...@gmail.com> wrote in
message news:uEABi473...@TK2MSFTNGP02.phx.gbl...

> Hang on guys...
>
> What's the syntax for Application.Contents?
>
> Application["TranslateDomain"]
> or
> Application.Contents("TranslateDomain")
> or
> Application.Contents["TranslateDomain"]
>
> Thanks,
>
> Felipe
>
>
I believe it's:
Application.Contents("TranslateDomain")

Look up "empirical" :)

Evertjan.

unread,
Jul 7, 2008, 4:48:03 AM7/7/08
to
Joe Fawcett wrote on 07 jul 2008 in microsoft.public.scripting.jscript:

> "Carlos Felipe França da Fonseca" <carlosfel...@gmail.com> wrote
> in message news:uEABi473...@TK2MSFTNGP02.phx.gbl...
>> Hang on guys...
>>
>> What's the syntax for Application.Contents?
>>
>> Application["TranslateDomain"]
>> or
>> Application.Contents("TranslateDomain")
>> or
>> Application.Contents["TranslateDomain"]
>>
>>

> I believe it's:
> Application.Contents("TranslateDomain")
>
> Look up "empirical" :)

A collection is not a jscript object, methinks.

Collections define their elements inside (),
objects define their elements inside [],
arrays also define their elements inside [].

Collection of ids:
getElementById()

Object existing of a single element:
getElementById('myIdea')

Collection of TagNames:
getElementsByTagName()

Object existing of all divs:
getElementsByTagName('div')

A single element of that object,
in itself also an object:
getElementsByTagName('div')[1]

Joe Fawcett

unread,
Jul 7, 2008, 11:50:45 AM7/7/08
to
A five minute experiment gave me this:

<%@ language="JScript" %>
<%

Application.Contents("One") = 1;
Application("Two") = 2;
var enumApp = new Enumerator(Application.Contents);
for (; !enumApp.atEnd(); enumApp.moveNext())
{
var oItem = enumApp.item();
Response.Write(oItem + ": " + Application(oItem) + "<br>");
}
Response.Write(Application.Contents("One") + "<br>");
Response.Write(Application("Two") + "<br>");

%>

Not sure why that was so hard, the output was:

One: 1
Two: 2
1
2


--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"Evertjan." <exjxw.ha...@interxnl.net> wrote in message
news:Xns9AD46DD6...@194.109.133.242...

Anthony Jones

unread,
Jul 8, 2008, 4:28:52 AM7/8/08
to
"Evertjan." <exjxw.ha...@interxnl.net> wrote in message
news:Xns9AD46DD6...@194.109.133.242...

> Joe Fawcett wrote on 07 jul 2008 in microsoft.public.scripting.jscript:
>
> > "Carlos Felipe França da Fonseca" <carlosfel...@gmail.com> wrote
> > in message news:uEABi473...@TK2MSFTNGP02.phx.gbl...
> >> Hang on guys...
> >>
> >> What's the syntax for Application.Contents?
> >>
> >> Application["TranslateDomain"]
> >> or
> >> Application.Contents("TranslateDomain")
> >> or
> >> Application.Contents["TranslateDomain"]
> >>
> >>
> > I believe it's:
> > Application.Contents("TranslateDomain")
> >
> > Look up "empirical" :)
>
> A collection is not a jscript object, methinks.
>
> Collections define their elements inside (),
> objects define their elements inside [],
> arrays also define their elements inside [].
>
> Collection of ids:
> getElementById()
>

No getElementById is a function. Creating a mental model that this is a
collection is IMO detrimental to a clear understanding.

> Object existing of a single element:
> getElementById('myIdea')
>

Calling the function returns a value. The functions parameter specifies a
key which the function uses internally to select a value to return.

> Collection of TagNames:
> getElementsByTagName()
>

getElementsByTagName is also function.

> Object existing of all divs:
> getElementsByTagName('div')
>

Return an array of values, in this case the values are HTML Div Element
objects

> A single element of that object,
> in itself also an object:
> getElementsByTagName('div')[1]

Get an array of HTML Div Element objects then use an array indexer [1] to
retrieve the second entry in the array.

Anthony Jones

unread,
Jul 8, 2008, 4:58:26 AM7/8/08
to
"Carlos Felipe França da Fonseca" <carlosfel...@gmail.com> wrote in
message news:uEABi473...@TK2MSFTNGP02.phx.gbl...

> Hang on guys...
>
> What's the syntax for Application.Contents?
>
> Application["TranslateDomain"]
> or
> Application.Contents("TranslateDomain")
> or
> Application.Contents["TranslateDomain"]
>


Attempting to use [ ] on a COM object such as Application will result in
Method or Property not supported error.

In JavaScript the [ ] syntax allows arbitary named attributes to be added
and accessed on an object. Standard COM objects such as those in ASP do
not support this.

Application("TranslateDomain") works since JScript co-operates with COM.

x("y") where x is a COM object is handled by JScript by the assumption that
there is a default member defined on x and that his member is a property.
JScript transforms this to method call on x which is the get accessor of the
default property. In the case of Application the default property is Value
therefore:-

var val = Application("y")

in effect becomes a simple method call:-

var val = Application.get_Value("y")

where x("y") is on the LHS of = it becomes an assignment and the put method
of the default property is used to which the value parameter is passed
result of the RHS expression:-

Application("y") = a + b

in effect becomes another method call:-

Application.put_Value("y", a + b)

The Application.Contents property is an object whose default property is
.Item. Application.Contents.Item and Application.Value are equivalent.

Evertjan.

unread,
Jul 8, 2008, 6:11:11 AM7/8/08
to
Anthony Jones wrote on 08 jul 2008 in
microsoft.public.scripting.jscript:

>> Collection of ids:
>> getElementById()
>>
>
> No getElementById is a function. Creating a mental model that this is
> a collection is IMO detrimental to a clear understanding.

You could also call getElementById a string.

It calls a single element of the collection of ids in the document or in
part of that.


>> Object existing of a single element:
>> getElementById('myIdea')
>>
> Calling the function returns a value. The functions parameter
> specifies a key which the function uses internally to select a value
> to return.

That is implementation, if I understand your words.

In common words it returns [the pointer to] the element.

>> Collection of TagNames:
>> getElementsByTagName()
>>
>
> getElementsByTagName is also function.

You are misreading I did not write "is".

It calls/returns a collection of a specified tagName out of the
collection of tagNames.


>> Object existing of all divs:
>> getElementsByTagName('div')
>>
> Return an array of values, in this case the values are HTML Div
> Element objects

Values are never objects, they are pointers to objects.



>> A single element of that object,
>> in itself also an object:
>> getElementsByTagName('div')[1]
>
> Get an array of HTML Div Element objects then use an array indexer [1]
> to retrieve the second entry in the array.

That was the whole point to give some logic to the difference between

xxx() for to get collections in general, a specified function indeed.

and

xxx[] to get an element of an array or an object.

Anthony Jones

unread,
Jul 8, 2008, 8:56:11 AM7/8/08
to
"Evertjan." <exjxw.ha...@interxnl.net> wrote in message
news:Xns9AD57BEE...@194.109.133.242...

> Anthony Jones wrote on 08 jul 2008 in
> microsoft.public.scripting.jscript:
>
> >> Collection of ids:
> >> getElementById()
> >>
> >
> > No getElementById is a function. Creating a mental model that this is
> > a collection is IMO detrimental to a clear understanding.
>
> You could also call getElementById a string.
>

You could call an elephant a horse if you wanted but I'm not quite sure why
you would want to. ;)

> It calls a single element of the collection of ids in the document or in
> part of that.
>

It returns the first element in the document that has an Id that matches the
parameter. It is not productive to think of it any more than that.

>
> >> Object existing of a single element:
> >> getElementById('myIdea')
> >>
> > Calling the function returns a value. The functions parameter
> > specifies a key which the function uses internally to select a value
> > to return.
>
> That is implementation, if I understand your words.
>
> In common words it returns [the pointer to] the element.

The concept of a pointer is a C++ism that is not needed in JavaScript. The
behaviour of an object is defined and the fact that a variable is actually a
reference to an object is intrinsic. Unlike C++ you can't ever hold an
object 'by-value' in variable so there is no need to make such a
distinction.

(I'm having a Deja moment about having this same discussion re: this
distinction before).

>
> >> Collection of TagNames:
> >> getElementsByTagName()
> >>
> >
> > getElementsByTagName is also function.
>
> You are misreading I did not write "is".
>
> It calls/returns a collection of a specified tagName out of the
> collection of tagNames.

That is true this function does return a collection object.

>
>
> >> Object existing of all divs:
> >> getElementsByTagName('div')
> >>
> > Return an array of values, in this case the values are HTML Div
> > Element objects
>
> Values are never objects, they are pointers to objects.
>

As stated above such distinction is not really necessary, an "object value"
is implicit a reference to the object.

> >> A single element of that object,
> >> in itself also an object:
> >> getElementsByTagName('div')[1]
> >
> > Get an array of HTML Div Element objects then use an array indexer [1]
> > to retrieve the second entry in the array.
>
> That was the whole point to give some logic to the difference between
>
> xxx() for to get collections in general, a specified function indeed.

However your list of examples showed one function getting an element and
another function getting a collection (which is an object itself) of
objects. Both are just simply functions. You said earlier:-

"Collections define their elements inside (), "

They don't. () simply means call the function on LHS with the parameters
listed. As I described in another reply in this thread there is some
special handling of () in JScript where the LHS is an ActiveXObject but
neither of your examples are of that type, they are both simply function
calls.

Here is an example of the sort of collection access I think you were
refering to:-

var col = document.getElementsByTagName("TR");
alert(col("someid").innerText);

JScript converts col("someid") to a col.get_item("someid") function call
(item being the default property), of course JavaScript in something like FF
just errors saying col is not a function.


>
> and
>
> xxx[] to get an element of an array or an object.
>

Specifically [ ] means 'of the object supplied on the LHS access the
attribute specified'.

For example to the above example you could add:-

alert(col["length"]) which is equivalent to alert(col.length)

Similarly alert(col["1"].innerText) is equivalent to alert(col[1].innerText)

Also equivalent is alert(col.item(1).innerText) and alert(col(1).innerText)

The COM objects that are returned by MSHTML implement the IDispatchEx which
supports the implementation of [ ] on these objects.

Using [ ] on COM objects that do not implement IDispatchEx will return
undefined or will throw an error.

Old Pedant

unread,
Jul 11, 2008, 8:33:01 PM7/11/08
to
> Application("TranslateDomain") works since JScript co-operates with COM.
>
> x("y") where x is a COM object is handled by JScript by the assumption that
> there is a default member defined on x and that his member is a property.
> JScript transforms this to method call on x which is the get accessor of the
> default property. In the case of Application the default property is Value
> therefore:-
>
> var val = Application("y")
>
> in effect becomes a simple method call:-
>
> var val = Application.get_Value("y")

Actually, that's not quite pedantic enough.

In point of fact, the ActiveX interface handler (in common to both JS and
VBS) will first try to see if indeed there *IS* a default *METHOD* property
on the object. If not, it then checks to see if there is a default property
on the object that is itself an object.

The Application object does *NOT* have any default method property. It
does, however, have a default OBJECT property named Contents.

So then the call is transformed, automatically, into
var val = Application.Contents("y")

The default "get" property on the Contents collection (yes, it's a
collection) is Item, so now you are actually invoking:
var val = Application.Contents.Item("y")

Since JS doesn't have the handy TypeName function, it's easier to demo this
in VBScript code:

******** junk.asp ********
<%
Session("foo") = "bar"

Response.Write "TypeName(Session) is " & TypeName(Session) & "<br/>"
Response.Write "TypeName(Session.Contents) is " & TypeName(Session.Contents)
& "<br/>"
Response.Write "TypeName(Session.Contents.Item(foo)) is " &
TypeName(Session.Contents.Item("foo")) & "<br/>"
Response.Write "TypeName(Session(foo)) is " & TypeName(Session("foo")) &
"<br/>"
%>
******************

The output of that is, not horribly surprisingly:

TypeName(Session) is ISessionObject
TypeName(Session.Contents) is IVariantDictionary
TypeName(Session.Contents.Item(foo)) is String
TypeName(Session(foo)) is String

I used Session so as not to litter up my app space awaiting a restart. But
honest, they are implemented the same way.

And all of this, of course, is essentially the same thing we see when people
use
RS.Fields.Item("foo").Value
instead of allowing JS/VS to supply all the defaults and just using
RS("foo")

Incidentally (or maybe not so incidentally), you *WLL* get MEASURABLY better
performance by using just
RS("foo")
and letting VBS/JS/COM do all the selection of defaults for you. Again,
this is because each extra byte code token added to the compiled form of JS
or VBS requires 60 to 100 lines of C++ code to execute, and the
COM-default-property-resolution code is considerably smaller than that.
Idiot DreamWeaver designers should take note. Not that they will at this
late date.

Old Pedant

unread,
Jul 11, 2008, 8:40:01 PM7/11/08
to
Not likely anybody will read this at this late date, but w.t.h.

The results of doing this on a recordset:

Response.Write "TypeName(RS) is " & TypeName(RS) & "<BR/>"
Response.Write "TypeName(RS.Fields) is " & TypeName(RS.Fields) & "<BR/>"
Response.Write "TypeName(RS.Fields.Item(0)) is " &
TypeName(RS.Fields.Item(0)) & "<BR/>"
Response.Write "TypeName(RS.Fields.Item(0).Value) is " &
TypeName(RS.Fields.Item(0).Value) & "<BR/><HR>"

are these:

TypeName(RS) is Recordset
TypeName(RS.Fields) is Fields
TypeName(RS.Fields.Item(0)) is Field
TypeName(RS.Fields.Item(0).Value) is String

The difference between this and Session or Application object is, of course,
that the elements of the Fields collection are themselves objects, so one
more default property (Value) is needed to get to the data you are commonly
interested in.

Dave Anderson

unread,
Jul 14, 2008, 8:33:32 AM7/14/08
to
Old Pedant wrote:
> TypeName(RS) is Recordset
> TypeName(RS.Fields) is Fields
> TypeName(RS.Fields.Item(0)) is Field
> TypeName(RS.Fields.Item(0).Value) is String

...something that every JScript ASP coder knows by heart.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


0 new messages