Writing Web applications using VBScript and JScript (ii)

Source: Internet
Author: User
Tags bitwise operators execution iis
js|jscript|vbscript|web| programs use VBScript and JScript to write Web applications (ii)

My heart is flying


6. Data type
The data types of VBScript and JScript are quite different, and JScript has 6 data types: Numeric, String, object,
Boolean, NULL, and undefined. VBScript is a variant of only one data type, but its subtypes are quite rich. Special
It is the fine division of numerical types that makes it more reassuring to perform precise numerical computations. And in line with the 2nd
The formatting feature makes data processing more handy. For documentation on this, please refer to Microsoft's MSDN.

7, operator
There are also some differences between VBScript and JScript in terms of operators:
For example, VBScript adds the arithmetic operator "&" for string concatenation, the "is" operator for object comparisons, and so on.
However, JScript provides a much larger number of operators than VBScript, such as the accumulator decrement operator "+ + 、--", a set of bitwise operators
And typeof, Delete, and other miscellaneous operators. Information about this is very detailed in MSDN, not to be repeated here.

8, string processing
The string processing of VBScript and JavaScript used to be the focus of netizens ' contention that the handling of strings was essentially
, the reason why I put forward this part alone, but also want to cause netizens to do some more detailed discussion.
In VBScript, strings are just a simple data type and provide a very rich string-handling function,
For example:
Asc,chr,instr,instrrev,join,lcase,ucase,left,right,len,ltrim,rtrim,trim,mid,replace,
Space,string,split,strcomp,strreverse
Therefore, a large number of netizens think that VBScript's string processing function is simpler and more powerful than JScript.

But I don't think so. Simplicity is possible, but when it comes to power, I think JScript is more powerful. In JScript,
A string is not only a data type, but also a special kind of object. As an object of method, he not only provided the above
Almost all of the functions of string functions in VBScript, and matching regular expressions can provide more robust functionality.

A typical application is a fuzzy search of strings, look at the following example:
I want to replace the possible spellings of chen0,chen1,chenk,chen99 in an article with joyasp:

var txt = mytextfile.readall ();
var re =/chenk?\d?\d?/gi;
txt = txt.replace (Re, "joyasp");

This usage is especially useful when you cannot accurately predict which strings are being processed. Friends who are familiar with Unix,c,c++,perl may
Not unfamiliar with regular expressions, please refer to the relevant articles on this subject.


Two languages are used simultaneously in the same Web page

You can use a different scripting language in the same Web page. There are several possible reasons for doing this:
A, in a program to make full use of the advantages of various languages.
B, the existing code you may be facing is written in a language you are unfamiliar with. For example, the DTC is written in JScript, and the
The language you are familiar with is VBScript.
In most cases, you can mix several scripting languages on the same Web page and they can work well with each other.
Scripts written in one language can invoke programs written in another language and can share global variables. But sometimes
There will still be a little bit of a problem, now to explain.

1. When you call a JScript function from VBScript, notice that parentheses are needed during the call, even if the function does not
This is required for setting parameters. For example, a call should look like this:

returnvalue = Call_jscript_function ()

If you forget the braces, then the value returned by the function is not the value you want, but a function that contains the
The body of VBScript could not explain the object.

2, the server script execution order
Commands that are enclosed in <%%> delimiters are called Master script commands, and the main script commands run sequentially, from beginning to end. Of course, you can
To define a callable program (function or subroutine) in a server script. That way, if you need to
They can be invoked at any time.
All master script commands must be written in the same language, that is, the <%@ language=xxxxx%> instructions in front of the Web page
The scripting language as specified in. Therefore, you cannot mix several scripting languages in a Master script command. You might
Say "Wait". In theory, it is absolutely possible to put server scripts in the <script> unit. Just like the following example:

<%response.write ("I Love joyasp!") %>
<script Language=vbscript runat=server>
Response.Write ("I Love my heart fly, too.")
</SCRIPT>

However, you will be controlled by the order in which the IIS ASP handlers are executed. For example, if you create a server script and
Run it in IIS 4.0 and you'll find that the order of execution might be this:

1 <SCRIPT> unit scripts for non-default languages
2 Main script command
3 <SCRIPT> unit script for default language

The order above is largely dependent on the loading order of the ActiveX scripting language engine, while the ASP handlers in IIS can
Can change in the future. Therefore, I am not very much in favor of writing code in this way, suggest that you are only the <SCRIPT> unit
For a function or subroutine, or to use it only for other encodings unrelated to the execution order.

3, the sequence of client script blocks
The order in which,<script> blocks appear in a Web page when you mix several languages on a client is important, and sometimes shadows
Rang to see if they could work properly. Take a look at the following simple example, which is called in a VBScript script with a
Functions written by JScript:

<script language= "VBScript" >
' Invoke a JScript function
her = "Lucy"
Loveher = Jsfuncloveher (Her)
document.write ("Top Secret Information:" & Loveher)
</SCRIPT>

<script language= "JavaScript" >
function Jsfuncloveher (ARG) {
Return "white, birds and Moslem all want to bubble" + her + "MM:-)";
}
</SCRIPT>


It won't do any work. To be more clear, document.write () writes an empty string to the Web page. For
What the? Quite simply, the following Java Script <SCRIPT> block has not been read out while processing the VBScript block, without
For parsing, so the Web page cannot use it. When a browser processes a script block in a Web page, it is top-down.

In this example, you can solve this problem by simply changing the order of the script blocks. However, the fact that such problems
Not so common, in most cases the functions and subroutines contained in,<script> only when the entire Web page is completely downloaded
Down and all the units can be used before it can be invoked. However, you still have to remember that the page is based on a certain
In order to deal with, the <SCRIPT> blocks of different languages are handled separately.



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.