Writing Web applications using VBScript and JScript (iii)

Source: Internet
Author: User
Tags array length arrays lowercase object model variable javascript array
js|jscript|vbscript|web| programs use VBScript and JScript to write Web applications (iii)

3, case-sensitive and naming habits
JScript is strictly case-sensitive: in each JScript keyword, in all parts of each JScript namespace,
You can use uppercase and lowercase letters in a proper combination. This includes all the key to the object model you use
Word. For example, when you use an ASP to response objects, you must use uppercase and lowercase letters (such as Response.Write) correctly.
Otherwise, JScript will resolutely refuse to admit it. Similarly, if you write a handler for the DHTML onclick event, if you use the
The casual use of uppercase and lowercase forms that occur frequently in Visual Basic may not be recognized by JScript.

VBScript does not distinguish between uppercase and lowercase letters. In a way, this careless case of carelessness even when you use
VBScript does not have any problems accessing the cells written by JScript. Two scripts are given in the following example. First
One is written in JScript and includes a global variable (CTR) and a function (doubleme). A second
The script is written in VBScript and is a button handler that can call a JScript function and report the global
The value of the variable.

<script language=javascript>
var Ctr;
function Doubleme (anumber) {
if (parseint (CTR)) {
CTR = ctr + 1;
}
else{
CTR = 1;
}
return anumber * 2;
}
</SCRIPT>

<script language= "VBScript" >
Function Btn1_onclick ()
Numbertodouble = 12
MsgBox "The Doubled number =" & Doubleme (numbertodouble)
MsgBox "Your have doubled the number" & CTR & "Times."
End Function
</SCRIPT>

In the VBScript script, it's obvious that I didn't use the letter size correctly when I mentioned the Doubleme function and the CTR variable.
Write, but the program still works well. That's a good news. And the bad news is that under these circumstances you must note
The capitalization of the letter: if the JavaScript script in the Web page contains cells that can only be written in uppercase and lowercase letters
Differentiate, for example, a function called a timer () and a global variable called a timer, and so on. Unfortunately, even though such a compilation
Code is not very good, but sometimes in your Web page or you may encounter the original encoding.

Use the name of a JScript unit as a string parameter in a function call

If JScript includes cells that can only be distinguished by the case of letters, VBScript will look at them as
(That is, it does not distinguish between uppercase and lowercase). VBScript can only look at the differences, regardless of the case, they are not the same,
So it recognizes only one JScript unit. In other words, if VBScript first finds the name timer ()
function, it cannot find a global variable called a timer, and vice versa. Even if you're in VBScript code,
It's very important to make a difference. The result is the same. Because VBScript thought that when they were dealing with these names, they had only one
Kind of writing. Unfortunately, there is no other workaround, except in the case of JScript code that does not take advantage of these
A small difference to distinguish between different function names.

It is not uncommon to use a cell name as a parameter, except in some special cases. One of the special cases is in the visual
In the Script object model in InterDev 6.0. I'll use it as an example, and you can think of it as the same
The processing criteria of the case.

The Scripting Object model for Visual InterDev 6.0 is written in JScript. You can also use VBScript to write your own
Encoding that can be used in conjunction with a scripting object model written in VBScript case sensitivity. Sometimes, you can not
Call a method directly unless you pass the name of the method to a JScript function, which is called by the function.
Method.

A typical example is the warning method, which you can use to bind a method to a particular event. In the following example
Child, the onmouseover event of a button is bound to the Changecaption () event handler.

<script language= "VBScript" >
Function Setadvisemethods ()
Btn1.advise ("onmouseover", "changecaption ()")
End Function
</SCRIPT>

Because you send these names as strings to a JScript function, you must use the correct case representation.
JScript automatically checks the names with its case-sensitive rules, and if the capitalization is not correct, they will not be found.

4. Transfer arrays from VBScript to JScript
Sometimes a VBScript program transmits an array as one of its arguments, or as its return value. You can start with JScript
, but you must convert the VBScript array into an available JScript array. You just need to be in a JScript function
It's OK to create a VBArray object and convert it into a JScript array with ToArray.

Note: JScript does not support multidimensional arrays, and if the original VBScript array is multidimensional, after toarray conversion it becomes a
A one-dimensional, JScript array. In the example below, there is a VBScript script that creates an array and a JScript
Script that will show you how to get and use this array:

<script language= "VBSCRIPT" >
Function Makearrayvb ()
' Create a VBScript array
Dim Anarray (1,1)
Anarray (0,0) = "0,0"
Anarray (0,1) = "0,1"
Anarray (1,0) = "1,0"
Anarray (1,1) = "1,1"
MAKEARRAYVB = Anarray
End Function

<script language= "JavaScript" >
accessing VBScript arrays in JScript scripts
function Getvbarray () {
var arrayobj;
var Jsarray;
Arrayobj = Makearrayvb ();
Jsarray = VBArray (arrayobj). ToArray ();
Alert ("VBScript Array length =" + jsarray.length);

Display the contents of an array
for (i=1;i<=jsarray.length;i++) {
Alert (jsarray[i-1]);
}
}
</SCRIPT>
However, in the current VBScript (4.0), the converse is not possible. Which means you can't convert a JavaScript array into a
is an array of VBScript. If you want to use a JavaScript array in a VBScript program, you can use the following procedure:
Converts a JScript array into a different structure, such as converting to a delimiter-delimited string, so that VBScript can make
Use it. For example, you can use the ToString function to convert an array into a comma-delimited, unrestricted string. This way, in
In VBScript you can use the Split function to divide it into different units. It is obvious that this method does not work in many cases, but sometimes
And it does work.

The above Rorillo to write a lot of, hoping to be helpful to netizens, also want to discuss some issues.
Finally, I wish friends Happy scripting!!

My heart is on the fly



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.