There are two conditions that are essential to learning a programming language. The first is the combination of theory and practice, in the actual routine to verify the theory of books can deepen your understanding of the theory, the second is to learn to summarize, to learn from the experience in the use of learning, as a kind of experience or lessons to refine and in the future application of the improvement, Will certainly improve your understanding of this programming language. The following is the author of the study and use of ASP programming in a little experience, hope to be helpful to everyone.
There are two conditions that are essential to learning a programming language. The first is the combination of theory and practice, in the actual routine to verify the theory of books can deepen your understanding of the theory, the second is to learn to summarize, to learn from the experience in the use of learning, as a kind of experience or lessons to refine and in the future application of the improvement, Will certainly improve your understanding of this programming language. The following is the author of the study and use of ASP programming in a little experience, hope to be helpful to everyone.
Interaction between VBS CRIPT and JS cript in ASP pages
The ASP has the ability to manage scripting programs in different languages and can automatically invoke the appropriate scripting engine to interpret script code and execute built-in functions. The ASP development environment provides two scripting engines, the VBS CRIPT (default) and the JS Cript. However, developers are not limited to using both languages, and can use any scripting language if they can provide the right ActiveX scripting engine.
Scripting languages are often chosen for a number of different reasons: it may be the most familiar language for developers, probably the most characteristic support for a given project, and possibly the most efficient. Different environments and requirements allow us to focus on different factors when choosing scripting languages, and at some point we face the problem that the selected scripting language does not directly provide functions that are intrinsic to other languages, or that a script has been written but used in another scripting language.
What should I do now? Do you need to rewrite these scripts with the scripting language you are currently using? Or is it possible to invoke a built-in function of another scripting language in a scripting language? This article is to explain how to make the VBS cript script and JS Cript script interact in ASP application to maximize the feature support of both scripting languages.
One, VBs cript and JS cript built-in functions
In the VBS cript and JS Cript, there are a number of built-in function functions that are the same or similar. However, functions built into a scripting language do not always have corresponding functions in another scripting language. For example, the VBs Cript provides a number of functions for manipulating strings and formatting data that do not exist in the JS Cript. These functions include StrReverse (), Filter (), and FormatCurrency (). On the other hand, the functions provided by Js Cript for managing arrays, string encoding, and so on are not defined in the VBS CRIPT, such as join (), reverse (), POW (), bitwise operation, Escape (), and unescape ().
So what if you need a VBS CRIPT function in a JS cript program?
Two, different kinds of scripts to call each other
If you need to call a function built into a VBS cript in a JS cript script, you should write a VBS CRIPT user-defined function (where the VBS CRIPT built-in functions are called), and then in the JS Cript script, like calling public JS Call this user-defined function like the Cript function.
For example, if the VBS CRIPT built-in function to invoke is FormatCurrency (), you can declare the following custom function:
< s cript language= "VBs cript" runat= "SERVER" >
Function Formatvalue (Value)
Formatvalue = FormatCurrency (Value)
End Function
</s cript>
Next in the JS Cript code can be like ordinary JS cript function like Call Formatvalue (). In a similar way, you can also implement the VBS CRIPT code to call the JS Cript function.
Applying the same rules, we can invoke any user-defined function within any script. However, to call a cript process (SUB) without parameters from the JS Cript script should be noted slightly, at this point in the JS Cript should be called as a JS cript function without parameters, such as calling the VBS CRIPT SUB foo process with foo ().
Third, data sharing
It is useful to mix the VBS CRIPT and JS Cript functions in some situations, but it can also be useful to share data between scripts in different languages. The way to implement this sharing is simple: regardless of the language you are using, you can refer to any variable that is declared at the page level.
Objects are similarly used, and you can choose the appropriate language to read, modify, or invoke the method of the object. Of course, the properties and methods of a given object are defined by the language that created the object instance. As in the procedure call of the example VBS CRIPT, when you call a method without a parameter in a VBS CRIPT object from JS Cript, its calling method also follows the calling rule of the JS Cript, and vice versa.
Iv. Array Management
The problem of array sharing is a little more complicated. Although arrays can be shared among different language scripts like other variables, you must be aware of compatibility issues.
The VBS CRIPT array can be referenced by the VBS CRIPT notation under JS Cript, that is, the array element is referenced by MyArray (2) instead of the JS cript reference symbol myarray[2]. In addition, you can use a special JS Cript object--vbarray object to convert the VBS CRIPT array to a JS cript array. The following code creates the JS cript array myjsarray from the VBS CRIPT array Myvbarray:
var Temp = new VBArray (Myvbarray)
var Myjsarray
Myjsarray = Temp.toarray ()
The code above first creates a temporary VBArray object and then uses its ToArray () method to convert itself to a JS cript array. You can then use myjsarray like a regular JS cript array, such as myjsarray[1]. It should be noted, however, that the ToArray () method converts a multidimensional vbarray into a one-dimensional JS cript array.
Referencing the JS Cript array from the VBS CRIPT is more complex. Although we can directly access the methods and properties associated with the JS Cript array in the VBS CRIPT, there is no way to directly access the individual elements of the JS Cript array. That is, we can read the length properties of the JS Cript array in the VBS CRIPT script as follows:
x = Myjsarray.length
But the single element of the array cannot be read directly, the following VBS CRIPT code is incorrect:
x = Myjsarray (3)
One possible way to resolve this problem is to perform a conversion process, as shown in the following code, where the VBS CRIPT is assumed to be the default scripting language:
<%
Dim Temp
Dim Myvbarray
Temp = Myjsarray.join (",")
Myvbarray = Split (Temp, ",")
%>
The JS Cript join () method here converts the array myjsarray element to a comma-delimited string, and the VBS CRIPT split () function converts the string to a VBS CRIPT array. Note that here we are calling the JS Cript join method under the VBS CRIPT environment. In this example, we can simulate the ToArray () method of the VBArray object of JS Cript by customizing the VBS CRIPT function to convert the JS cript array to the VBS CRIPT array.