Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is JScript a 'first class' equal peer to VBscript in NON-dotNet ASP?

Posted on 2003-11-14
6
Medium Priority
?
377 Views
Last Modified: 2006-11-17
I need to write a few new scripts for an ancient app running in a pre-.NET ASP environment. To tell the truth, I hate VBscript and Visual Basic syntax in general with a passion. JScript isn't much better, but at least it uses halfway civilized syntax (I happen to like punctuation better than verbosity. Ok, and I keep forgetting the )@$*( 'Then' after 'If' statements... grrr....).

Anyway, is JScript TRULY an equal peer to VBscript insofar as pre-.NET ASP is concerned?  Are all the objects available to VBscript (Server, Response, etc.) available to JScript? Are there any innate capabilities of VBscript relevant to ASP that simply aren't available (or are massively kludged) in JScript?

I'm assuming the answer is a resounding 'no', but can you mix languages in a single page (using multiple <script language="xxx" runat="server" blocks specifying different languages in different places)? And if you can, do they share a common object space? For instance, can you Dim a String variant in a block of VBscript and assign it a value near the top of the page, then do something with that variable in a block of JScript further down the page? How about complex objects? Say, an object defined using VBscript syntax, possibly created within a VBscript block, then called by a JScript block further down the page?

Is there any good online reference to using JScript in the context of pre-.NET ASP? I've been searching for over an hour, but everything I keep finding is either

* an article about using VBscript that just happens to contain the word "JScript" somewhere

* an article about client-side JScript within IE

* An article about something .NET related that, like the mountain of VBscript articles, just happens to mention JScript in passing.
0
Comment
Question by:jskubick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 9749030
I agree that JScript is a nicer language to work with then VBScript. In fact in older ASP versions, JScript had more possibilites then VBScript (although there probably also were some things in VBScript that weren't possible in JScript).

In my opinion you can use Jscript just as well as VBScript in ASP.
It it also nice to mix languages if needed. You can even use perlscript, if you install it.
Mixing languages is no problem, they all will be have access to public variables.

There one thing that is really different in VBScript and JScript: arrays. A VBScript and a JScript array are completely different things. Now that I talk about arrays: VBScript has truly multi-dimensional arrays, while JScript hasn't.

The thing is that most ASP pages are written in VBScript, and if you want advice, then it's easier to get in in VBScript. I believe however that most ASP programmers als have quite a knowledge of client-side javascript (look at the expert-rankings here on EE, you'll see that most high ranked ASP maybe are not top-javascript experts, but have a considerable amount of point in the javascript area).

If you hate to program in VBScript, there's really nothing against using JScript from the point of possibilites.


0
 

Author Comment

by:jskubick
ID: 9749439
Is there a JScript equivalent to
<% Option Explicit %> ?

How about sharing variables? I assume a variable assigned a value of null by vbscript will have a value of null when checked by JScript, but does vbscript's 'empty' map directly to jscript's 'undefined'? Aside from not trying to share arrays, are there any other not-necessarily-obvious things that will cause JScript to crash and burn, even though the same thing theoretically works from vbscript? Situations where one language expects something to pass by value where the other expects it to pass by reference, perhaps?
0
 
LVL 28

Accepted Solution

by:
sybe earned 500 total points
ID: 9749646
I don't know the answers to your question. the only way would to try it probably.

VBScript functions and Subs pass variables by default ByRef. To tell the truth I don't know about JScript.
VBScript function can have ByValue or ByRef before the parameter. I don't think JScript can.

<%
Function Demo(ByVal intIn)
    Demo = intIn + 1
End Function

Function Demo2(ByRef intIn)
    Demo2 = intIn + 1
End Function
%>

Somehow I sense that you are afraid to use JScript in ASP. I don't think that there is any reason for that. If you mix script-languages, then mind the arrays. Although JScript even has a VBARRAY:

varName = new VBArray(safeArray)
Arguments
varName
Required. The variable name to which the VBArray is assigned.
safeArray
Required. A VBArray value.

Example
The following example consists of three parts. The first part is VBScript code to create a Visual Basic safe array. The second part is JScript code that converts the VB safe array to a JScript array. Both of these parts go into the <HEAD> section of an HTML page. The third part is the JScript code that goes in the <BODY> section to run the other two parts.

<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!--
Function CreateVBArray()
   Dim i, j, k
   Dim a(2, 2)
   k = 1
   For i = 0 To 2
      For j = 0 To 2
         a(j, i) = k
         document.writeln(k)
         k = k + 1
      Next
      document.writeln("vbCRLF")
   Next
   CreateVBArray = a
End Function
-->
</SCRIPT>

<SCRIPT LANGUAGE="JScript">
<!--
function VBArrayTest(vbarray){
   var a = new VBArray(vbarray);
   var b = a.toArray();
   var i;
   for (i = 0; i < 9; i++)
   {
      document.writeln(b[i]);
   }
}
-->
</SCRIPT>
</HEAD>

<BODY>
<SCRIPT LANGUAGE="JScript">
<!--
   VBArrayTest(CreateVBArray());
-->
</SCRIPT>
</BODY>


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:sybe
ID: 9749654
A very big advantage of JScript is the ability to create enumerated script classes. In VBScript you can't do that.
0
 
LVL 28

Expert Comment

by:sybe
ID: 9749665
Jscript can measure milliseconds, VBScript has a minimal time-unit 1000/256 second.
0
 
LVL 28

Expert Comment

by:sybe
ID: 9749677
JScript has optional parameters to functions, VBScript hasn't
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question