JScript and VBscript

  • Thread starter Christopher Brandsdal
  • Start date
C

Christopher Brandsdal

If I have a .ASP page that runs JScript code - is it possible to include an
..ASP page that runs VBscript???
 
D

Dave Anderson

Atrax said:
you could convert one into a WSC and use that, or you could use
<script runat="server"> rather than ASP delimiters...

Server.Execute() is also available...


--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
R

Roland Hall

Be aware of the execution order:
1.. Script in <SCRIPT> elements in nondefault languages
2.. Inline script
3.. Script in <SCRIPT> elements in the default language
--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
 
D

Dave Anderson

Roland Hall said:
Be aware of the execution order...

Curiously enough, this can be "circumvented". A function (or Function or
Sub) can be called from any block regardless of which one defines it -- and
regardless of the "execution order".



--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
G

Guest

help & support, searching for information stored on this
computor,recieving genetic failure.
 
D

Dave Anderson

Mike Florio said:
Only limitation is that you can't pass a querystring to
Server.Execute().

I'd say there are a few more. The calling script shares no variables or
functions with the one being executed, for example.


--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
R

Roland Hall

Dave Anderson said:
Curiously enough, this can be "circumvented". A function (or Function or
Sub) can be called from any block regardless of which one defines it -- and
regardless of the "execution order".

Ok but wouldn't that require having knowledge of the order of execution?

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
 
M

Mark Schupp

Ok but wouldn't that require having knowledge of the order of execution?

No. Put the code in the different language into subroutines or functions
(not inline). Then call those functions in the desired order from inline
code in whichever language that you want to be "dominant".
 
R

Roland Hall

Mark Schupp said:
No. Put the code in the different language into subroutines or functions
(not inline). Then call those functions in the desired order from inline
code in whichever language that you want to be "dominant".

Correct. Without knowing the order of execution and not doing it as you
suggested means you could get into trouble, which is my whole point!

I prefer this answer: http://www.aspfaq.com/show.asp?id=2045 - It is better
not to mix inline code with script blocks runat=server but should you have
to, knowing the order of execution is better than not knowing.

Mixed-language script blocks not in subs/functions. They get executed out
of the order they were placed on the page.
http://kiddanger.com/lab/langorder.asp

<%@ Language=VBScript %>
<% Option Explicit %>
<script type="text/vbscript" language="vbscript" runat=server>
Response.Write("one <br />")
</script>
<script type="text/javascript" language="javascript" runat=server>
Response.Write("two <br />")
</script>
<%
Response.Write("three <br />")
%>
<script type="text/javascript" language="javascript" runat=server>
Response.Write("four <br />")
</script>
<script type="text/vbscript" language="vbscript" runat=server>
Response.Write("five <br />")
</script>

Mixed-language script blocks in subs/functions called from inline script.
They get executed in the order called from inline script.
http://kiddanger.com/lab/langorder2.asp

<%@ Language=VBScript %>
<% Option Explicit %>
<script type="text/vbscript" language="vbscript" runat=server>
sub vb1()
Response.Write("one <br />")
end sub
</script>
<script type="text/javascript" language="javascript" runat=server>
function js2() {
Response.Write("two <br />")
}
</script>
<%
vb1
js2
Response.Write("three <br />")
js4
vb5
%>
<script type="text/javascript" language="javascript" runat=server>
function js4() {
Response.Write("four <br />")
}
</script>
<script type="text/vbscript" language="vbscript" runat=server>
sub vb5()
Response.Write("five <br />")
end sub
</script>

Ridiculous example:

Default language VBScript, calling a JScript script block which calls a
VBScript script inline function and writes the result from inline vbscript.
If the ?n=# where # = a decimal number is not present, an error is called
from vbscript inline script to a vbscript script block sub to display an
error and syntax.

http://kiddanger.com/lab/langorder3.asp
http://kiddanger.com/lab/langorder3.asp?n=65535

<%@ Language=VBScript %>
<% Option Explicit %>
<script type="text/jscript" language="jscript" runat=server>
function jsHex(jsn) {
return vbHex(jsn);
}
</script>
<script type"text/vbscript" language="vbscript" runat=server>
sub showError()
Response.Write("<div style=""border: 1px solid black""><div
style=""border-bottom: 1px solid black; padding-right: 2px;
background-color: #ffe0e0""><span style=""color: white; background-color:
red; border-right: 1px solid black"">Error!</span> Value expected.</div>" &
vbCrLf & _
"syntax: http://kiddanger.com/lab/langorder3.asp?n=" &
server.HTMLEncode("<a decimal number>") & "<br />" & vbCrLf & _
"Ex. http://kiddanger.com/lab/langorder3.asp?n=546</div>")
end sub
</script>
<%
function vbHex(vbn)
vbHex = Hex(vbn)
end function

dim n
n = Request.QueryString("n")
if n = "" then
showError
else
Response.Write("Decimal: " & n & " = Hex: " & jsHex(n) & "<br />")
end if
%>

IMHO, not informing someone of the order of execution is ridiculous. That
was my whole point. I know it's possible to make it work but not knowing
could cause problems.

--

Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
 
D

Dave Anderson

Roland Hall said:
Correct. Without knowing the order of execution and not doing it as you
suggested means you could get into trouble, which is my whole point!

And your point is wrong. If you follow Mark's advice, you CANNOT get in
trouble, regardless of whether you know the order of execution or not.

...IMHO, not informing someone of the order of execution is ridiculous.
That was my whole point.

Which one was your whole point -- that it is ridiculous or that it could
lead to trouble?

I know it's possible to make it work but not knowing could cause problems.

Likewise with not knowing anything else about the technology you are working
with. What's your point (whole or otherwise)?


--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
R

Roland Hall

Dave Anderson said:
And your point is wrong. If you follow Mark's advice, you CANNOT get in
trouble, regardless of whether you know the order of execution or not.

If you do not know there is an execution order and you DO NOT put all
non-default language script in subroutines called from inline script then
you can get in trouble. How difficult is that for you to understand? Mark
obviously knows about the execution order and thus uses this coding
methodology. Where is the crime in letting others know WHY you should try
to do it the way Mark suggested? I know you prefer the "Dave Anderson, Just
Follow Me Blindly Method" but where is the education in that? Your
methodology doesn't work.

301 Error.
Dave's Response: Problem with your keyboard, go into the BIOS setup and
disable checking for the keyboard. You'll never experience this error
again. Don't ask questions. This is a need to know basis and I don't think
you need to know. You'll never need to know why if you just do as I say.

User replaces keyboard and still experiences same error. Perhaps it's not
plugged in? Educating the user in this case might be beneficial?! Perhaps
the color-coded ps/2 ports, the mouse and keyboard are plugged into, might
be reversed?! Or maybe the user's keyboard is wireless and the batteries
are dead?!

Educating someone as to WHY something should try to be done a certain way to
avoid possible errors is a good thing. Not educating someone as to WHY and
the possible errors that could occur is just plain dumb. If Aaron has a FAQ
re: this issue, perhaps there are a lot of people that need some education
regarding issues with the execution order of mixed-language server-side
script blocks with inline script and how to avoid them?!

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
 
D

Dave Anderson

Roland Hall said:
If you do not know there is an execution order and you DO NOT
put all non-default language script in subroutines called from
inline script then you can get in trouble.

Define trouble.

I think anyone with rudimentary troubleshooting skills can mix languages in
ASP without "getting in trouble". I would further suggest that someone
willing to use two languages is already savvy enough to explore the inherent
issues to a point of reasonable understanding.

But more to the point, order of execution is just SOMETHING TO KNOW about
ASP. If you create an instance of something with VBScript and don't know
that you're supposed to later set the variable reference to Nothing, you can
get in trouble. If you put objects into session or application variables,
you can get in trouble, whether you know it or not. If you don't understand
the difference between an object and its default property, you can get in
trouble.

BFD. Mixing scripting languages doesn't have to be intuitive, it merely
should be documented. And it is:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvid/html/msdn_vbnjscrpt.asp


[Incoherent "Dave Anderson, Just Follow Me Blindly Method" rant snipped]
If Aaron has a FAQ re: this issue, perhaps there are a lot of
people that need some education regarding issues with the
execution order of mixed-language server-side script blocks
with inline script and how to avoid them?!

My point is that people should understand the technology they are using, and
the existence of the FAQ is not inconsistent with that or anything else I
have said in this thread.


--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
R

Roland Hall

Dave Anderson said:
Define trouble.
Code not executing in the order you wanted it to?
I think anyone with rudimentary troubleshooting skills can mix languages in
ASP without "getting in trouble". I would further suggest that someone
willing to use two languages is already savvy enough to explore the inherent
issues to a point of reasonable understanding.
One does not define the other however, you did say 'suggest.' Using two
languages does not prove you know them. Also, knowing the two languages, in
this case JScript/Javascript and VBScript does not mean you understand the
order of execution of the ASP processor.
But more to the point, order of execution is just SOMETHING TO KNOW about
ASP.
That's all I have been saying. It is better to know than not know. From
now on, I'm drawing pictures. (O:=
If you create an instance of something with VBScript and don't know
that you're supposed to later set the variable reference to Nothing, you can
get in trouble.
Define trouble. (O:=
The same is true if you don't wear a condom.
If you put objects into session or application variables,
you can get in trouble,
Define trouble. (O:=
The same is true if you don't call her the next day.
whether you know it or not. n/a

If you don't understand
the difference between an object and its default property, you can get in
trouble.
Define trouble. (O:=
The same is true if you don't know the difference between your *ss and a
hole in the ground.
It could be.
Mixing scripting languages doesn't have to be intuitive, it merely
should be documented.
The Bible has been around for many years but how many cannot recite the 10
commandments?
There is a lot of documentation out there you and I have not read. Just
because it is documented doesn't mean it is known by the person trying to
implement it. None of my ASP books actually reference the execution order,
AFAIK. I read a post in here long ago and found out that way. I don't use
runat=server so I have never experienced this issue but it was by chance,
not by knowledge, even though it has been documented since 1998.
And it is:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvid/html/msdn_vbnjscrpt.asp
Perhaps Microsoft thought it was necessary for people to KNOW?!
My point is that people should understand the technology they are using,
I agree but you cannot know everything. This NG demonstrates that even the
most seasoned developer sometimes has to ask for help.
and
the existence of the FAQ is not inconsistent with that or anything else I
have said in this thread.
It's not just a river in Egypt anymore. (O:=

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.

-Technet Script Center-
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp
-MSDN Library-
http://msdn.microsoft.com/library/default.asp
 
D

Dave Anderson

"Roland Hall" "wrote":
This doesn't work - mismatch error

[client-side example]

That's irrelevant. This is an ASP forum, and the discussion has focused on
the behavior of asp.dll, not on that of a client-side browser. I note that
your code generates no errors for the following browsers (vacuously, of
course):

Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.5) Gecko/20031007
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2) Opera 7.11 [en]

In any case, it's unreasonable to assume you know the implemetation of
scripting support for every version of every browser. We *do* know and have
reasonable expectation of continued support for the behavior of asp.dll, and
that is the only thing that matters in here.

Change the order of the script blocks and it works:

Same fallacy...
It's modified a bit but not much. It's from some documentation
from Microsoft. It must be unreliable.

Cute. You quote an article titled "Using VBScript and JScript on a Web
Page", which specifically warns that this example ill not work. Rather than
show mixed scripting behavior to be "unreliable", you provide the evidence
that the documentation is correct for both the asp.dll behavior and for
Internet Explorer's client-side behavior.

Offering evidence that your argument is wrong is perhaps not the textbook
way of persuading people, but it *does* have the attraction of novelty.



--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top