A good programming language has two conditions that are essential, 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 in the study and use of ASP programming two experience, hope to be helpful to everyone.
interaction between VBScript and JScript within an ASP page
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, VBScript (default) and JScript. 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 about how to get VBScript scripts and JScript scripts to interact with each other in ASP applications to maximize the feature support for both scripting languages.
one, VBScript, and JScript built-in functions
In VBScript and JScript, 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, VBScript provides a number of functions for manipulating strings and formatting data that do not exist in JScript. These functions include StrReverse (), Filter (), and FormatCurrency (). On the other hand, the functions provided by JScript for managing arrays, string encodings, and so on are not defined in VBScript, such as join (), reverse (), POW (), bitwise manipulation, Escape (), and unescape ().
So what if you need a VBScript function in a JScript program?
two, different kinds of scripts to call each other
If you need to call a built-in function in VBScript in a JScript script, you should write a VBScript user-defined function (where the VBScript built-in function is called), This user-defined function is then called in a JScript script as if it were a public JScript function.
For example, if the VBScript built-in function to invoke is FormatCurrency (), you can declare the following custom function:
< SCRIPT language= "VBSCRIPT" runat= "SERVER" >
Function Formatvalue (Value)
Formatvalue = FormatCurrency (Value)
End Function
</script>
You can then call Formatvalue () like a normal JScript function in JScript code. You can also implement VBScript code to call a JScript function in a similar way.
Applying the same rules, we can invoke any user-defined function within any script. However, when you call a VBScript procedure (SUB) without parameters from within a JScript script, you should note that you should call it in JScript as if you were calling a JScript function without parameters, such as calling the VBScript Sub foo process with foo ().
third, data sharing
It is useful to mix VBScript and JScript functions in some cases, 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 with the procedure call in VBScript above, when you call a method of a VBScript object without parameters from JScript, the calling method also complies with the calling rules of JScript 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 VBScript array can be referenced in VBScript under JScript, that is, myarray (2) refers to an array element instead of a JScript array element reference symbol MYARRAY[2]. In addition, you can use a special JScript object--vbarray object to convert a VBScript array to a JScript array. The following code creates a JScript array Myjsarray from the VBScript 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 JScript array. You can then use myjsarray like a normal JScript array, such as myjsarray[1]. It should be noted, however, that the ToArray () method converts a multidimensional vbarray into a one-dimensional, JScript array.
Referencing a JScript array from VBScript is more complex. Although in VBScript we have direct access to the methods and properties associated with the JScript array, there is no way to directly access the individual elements of the JScript array. That is, we can read the length properties of the JScript array in the VBScript script as follows:
x = Myjsarray.length
But the single element of the array cannot be read directly, and the following VBScript 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 VBScript is assumed to be the default scripting language:
<%
Dim Temp
Dim Myvbarray
Temp = Myjsarray.join (",")
Myvbarray = Split (Temp, ",")
%>
The JScript Join () method here converts the array myjsarray element to a comma-delimited string, and the VBScript split () function converts the string to a VBScript array. Notice here we are calling the join method of JScript in a VBScript environment. In this example, we can simulate the ToArray () method of JScript's VBArray object by customizing the VBScript function to implement the conversion of a JScript array to a VBScript array.
Create a dynamic ASP page with a template
For the template, I think you may have some concepts, in Word, a lot of templates, design the approximate layout, you just fill in your own words that placeholder characters. The template here is probably the meaning, the relatively stable part of the page is fixed, the other part of the root of the different situation in the input of different content. In fact, there are templates in the Dreamweaver function, but the static, can only manually fill the content, and here is the dynamic automatic content fill.
First, let me explain why I use the template file. Sometimes, templates can bring you a more complete concept of Web page functionality and layout. When you see the template format for Word, you know what the final layout looks like, and here it is. For example, you can keep ASP statements and use different templates to create different page styles.
That way, you don't have to write different ASP pages for each different style of Web page, which obviously saves us a lot of time and effort. Also, template files can make it easier for you to browse the page code without worrying about your confusing ASP and HTML mix. You can just focus on the HTML and do not have to manage the ASP at all. Then there is, the touch board is very simple, you absolutely will soon be able to understand the handle. In this article, you will use a database-a very broad list of employees. Includes employee ID, name, photo, and work summary and photo footnotes. The following is the structure of this Access database:
FileName-Mydatabase.mdb
Table Name-Employees
Id
Automatic count (Autonumber)
FullName
Text-up to 100 characters
Picurl
Text-up to 255 characters
Duties
Annotation type
Piccaption
Text-up to 50 characters
A very simple database, right. Of course you can expand it as required, and that's your own business. I assume that you know the basics of the database so that I don't have to spend too much ink on it, but the code here is very simple, as long as you know something basic, you can read it. Once we have established the database, we can start creating the template file. This file is the skeleton of each page. I didn't use the form, that was a bit of a hassle, and I was lazy, and I didn't have to add, tag, because it was added to the ASP page. So in the end, it looks like this:
Full Name:
%name% < br>description of Duties:
%duties%
This is taken:%date%
Employee ID:%empid%
That's it! This is a simple template. Save it as template.tmp, and it will be referenced in the following ASP page. Note that we can add a variety of HTML tags to the template, you can completely define the structure and style of the page in the touch version, just like writing a Web page, just to mark the key points--notice the things around the%? That's the essence of the template. You may have noticed that the% of those% are corresponding to the fields in the database. Look at the following ASP code, how to read the template and database files, rub them together, and then output the HTML page we want.
That's all the code, it's simple, isn't it? It simply opens the template file, reads each row sequentially, and then replaces those%img%,%name% tags in the stencil with the actual field values that are read in the punch database. Furthermore, it interprets the carriage return in the large text in the "duties" field as an HTML carriage return, so as not to disrupt the entire layout format. What do you think? It's easy to handle. The template in some applications really can play wonders, save time and effort. In theory, you can also modify this code to read and write text using FileSystemObject so that the data is not necessarily stored in the database. In some applications, such as instant press releases, this may be more convenient.