Recommended: Use site maps to help search engines The goal of building a website is to increase visibility and increase user traffic. Search engine optimization is a way to increase website traffic. Another approach is to use a sitemap, which allows you to specify which pages a search engine contains or indexes. The concept of site map was originally created by Google
There are two conditions that are essential to learn a programming language well. One is to combine theory with practice, and verify the theory in the book through practical routines can deepen your understanding of the theory; the other is to learn to summarize, write down the experience and experience in learning and application, and refine it as an experience or lesson and improve it in future applications. This will definitely improve your understanding of this programming language. The following are two experiences in learning and using ASP programming, which I hope will be helpful to you.
Interaction between VBScript and JScript in ASP page
ASP has the ability to manage scripting programs in different languages and can automatically call appropriate scripting engines to interpret script code and execute built-in functions. The ASP development environment provides two scripting engines, namely VBScript (default) and JScript. However, developers are not limited to using only these two languages, and can use any scripting language as long as they can provide the appropriate ActiveX scripting engine.
The choice of scripting language is often based on many different reasons: it is probably the language that developers are most familiar with, maybe the one that provides the most featured support for a given project, or maybe the one that is most efficient. Different environments and requirements make us pay attention to different factors when choosing a scripting language, and at some point we face the problem that the selected scripting language cannot directly provide functions in other languages, or that a script has been written but uses another scripting language.
What should I do now? Do you need to rewrite these scripts in the current script language? Or, is it possible to call built-in functions of other scripting languages in one scripting language? What this article will explain is how to interact with VBScript scripts and JScript scripts in ASP applications to maximize the special support of the two scripting languages.
1. Built-in functions for VBScript and JScript
In VBScript and JScript, there are a large number of built-in functions that are the same or similar. However, functions built into one scripting language do not always have corresponding functions in another scripting language. For example, VBScript provides many functions for manipulating strings and formatting data, which do not exist in JScript. These functions include StrReverse(), Filter(), FormatCurrency(), etc. On the other hand, the functions provided by JScript for managing arrays, string encoding, etc. are not defined in VBScript, such as join(), reverse(), pow(), bit operations, escape(), and unescape().
So, what should I do if I need a VBscript function in a JScript program?
2. Mutual calls of heterogeneous scripts
If you need to call a built-in VBScript function in a JScript script, you should write a VBScript user-defined function (called VBScript built-in functions here), and then call this user-defined function in the JScript script just like calling a public JScript function.
For example, if the VBSCript built-in function to be called is FormatCurrency(), you can declare the following custom function:
| The following is the quoted content: < SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER> Function FormatValue(Value) FormatValue = FormatCurrency(Value) End Function < /SCRIPT> |
Next, in JScript code, you can call FormatValue() like ordinary JScript functions. VBScript code calls JScript functions can also be implemented using a similar method.
Applying the same rules, we can call any user-defined function within any script. However, when calling a VBScript procedure (Sub) without parameters from within a JScript script, you should pay attention to it. At this time, you should call it in JScript like calling a JScript function without parameters, such as calling the VBScript Sub foo procedure with foo().
3. Data Sharing
It is very useful in some cases to mix VBScript and JScript functions, but it can also be useful to share data between scripts in different languages. The way to implement this sharing is simple: no matter what language you are using, variables declared at the page level can be referenced arbitrarily.
The usage methods of objects are also similar. You can use a suitable language to read, modify properties or call objects. Of course, the properties and methods of a given object are defined by the language that created the instance of that object. As in the above example VBScript procedure call, when a method of a VBScript object without parameters is called from JScript, its calling method also follows the calling rules of JScript, and vice versa.
IV. Array Management
The problem of array sharing is a little more complicated. Although arrays can also be shared among scripts in different languages like other variables, it is necessary to pay attention to compatibility issues.
VBScript arrays can be referenced with VBScript symbols in JScript, that is, referring to array elements with myArray(2) instead of JScript's array elements referencing the symbol myArray[2]. In addition, you can also use a special JScript object - VBArray object to convert VBScript arrays into JScript arrays. The following code creates a JScript array myJSArray from the VBScript array myVBArray:
| The following is the quoted content: var Temp = new VBArray(myVBArray) var myJSArray myJSArray = Temp.toArray() |
The above code first creates a temporary VBArray object and then converts itself into a JScript array using its toArray() method. After that, myJSArray can be used like ordinary JScript arrays, such as myJSArray[1]. But it should be noted that the toArray() method will convert a multi-dimensional VBArray into a one-dimensional JScript array.
Referring to JScript arrays from VBScript is more complex. Although in VBScript we can directly access methods and properties related to JScript arrays, there is no way to directly access a single element of a JScript array. That is, we can read the length property of the JScript array in a 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)
A possible way to solve this problem is to perform a conversion process, as shown in the following code, where VBScript is assumed to be the default scripting language:
| The following is the quoted content: < % Dim Temp Dim myVBArray Temp = myJSArray.join(, ) myVBArray = Split(Temp, , ) %> |
The JScript join() method here converts the array myJSArray element to a string with a comma as a splitter, and the VBScript Split() function converts the string to a VBScript array. Note that we are calling the join method of JScript in the VBScript environment. According to this example, we can simulate the toArray() method of the VBArray object of JScript through custom VBScript functions to implement the conversion of JScript array to VBScript array.
Create dynamic ASP pages with templates
Regarding templates, I think everyone may have some concepts. There are many templates in word. After designing a general layout, you just need to fill in the placeholder characters in your own words. This is probably the meaning of the template here. The relatively stable part of the page is fixed, and other parts are inputting different contents in different situations. In fact, there is also a template function in DreamWeaver, but the static one can only fill content manually, and here is about dynamic automatic content filling.
First, let me explain why the template file is used. Sometimes, templates can give you a more complete concept of web page functions and layout. When you see the template format of Word, you will know what the final layout looks like, and the same is true here. For example, you can keep ASP statements and use different templates to create different page styles.
In this 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 energy. Moreover, template files can make it easier for you to browse page codes, and you don’t have to worry about the mix of ASP and HTML that makes you dizzy. You can just focus on HTML without having to worry about ASP at all. Another thing is that the touchpad is very simple and you will definitely understand it quickly. In this article, a database will be used - a widely used employee table. Includes employee ID, name, photo, as well as job summary and footnotes for photos. Here is the structure of this Access database:
| The following is the quoted content: File name - myDatabase.mdb Table name - Employees ID Automatic counting (Autonumber) FullName Text - up to 100 characters PicURL Text - up to 255 characters Duties Comment 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 you already understand the basic operations of the database, so I don’t have to spend too much effort on it. In fact, the code here is very simple. As long as you know some basic things, you can understand it. After establishing the database, we can start creating the template file. This file is the skeleton of each page. I didn't use the form, it was a bit troublesome, and I was lazy, and I didn't need to add it, tags, because that was to be added to the ASP page. So in the end, it looks like this:
| The following is the quoted content: Full Name: %name% < br>Description of duties: %duties% This picture was taken: e% Employee ID: %empID% |
That's it! This is a simple template. Save it as template.tmp and will reference it in the ASP page in the following. It should be noted that we can add various HTML tags to the template. You can completely define the structure and style of the web page in the touch version, just like actually writing a web page, just to mark the key points - have you noticed the things around those %? That's the essence of the template. Perhaps you have noticed that those % are surrounded by corresponding to the meaning of the field in the database. Take a look at the ASP code below, how to read the template and database files, knead them together, and then output the HTML page we want.
That's all the code, it's very simple, isn't it? All it does is to open the template file, read each line in order, and then replace the %img% and %name% tags in the template with the actual field values read in the database. Moreover, it interprets the carriage return in a large piece of text in the Duties field as the carriage return of HTML, so that the entire layout format will not be disrupted. How about it? It's easy to do it. Template can really play a miraculous role in some applications, saving time and effort. In theory, you can also modify this code and use FileSystemObject to read and write text, so that the data does not have to be stored in the database. In some applications, such as instant news releases, this may be more convenient.
Share: Commonly used ASP functions for web pages '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------