Introduction to ASP Programming (III): Contact script Program _asp Foundation

Source: Internet
Author: User
Tags close page
With the previous HTML in the form of reinforcement knowledge, is not thinking that the following can start the ASP trip? Not necessarily.
The general system has learned the ASP's programmer to be aware of: before the system learns the ASP's built-in object and the built-in component, learns the scripting language is always essential.
Why do you say that? Why do you want to learn scripting language? What's the relationship between ASP and scripting languages?

First of all, let's say ASP is what you are. ASP, the abbreviation for Microsoft Active Server Pages, is a server-side scripting environment that you can use to create interactive Web pages and build powerful Web applications. Can show that ASP is a server-based scripting environment, then understand why the ASP needs IIS support, because IIS is a common class of Web servers; That's why you learn scripting languages, because the ASP provides a scripting environment.

Again, the ASP is just an environment, not a language. If you really want to visualize that the ASP is a network programming language, it is also belong to a html+ script +asp provided with built-in objects and componentsA powerful blend of languages.

So, learning a little script is very important! In fact, whether it's a scripting language or any other language, I think the first thing I need to know is the various features covered by the language, including: data types, events, methods, objects, properties, syntax, and so onOf course, this is a lot of empty talk, as in the University class in a computer language class, the pure research is to feel some rope and tasteless. Or practical good, can solve the problem of the program is a good program (proof can catch mice cat is a good cat classic holy language, hehe)

Of course, the language of this thing still want you to study well, such as you write the absolute value of the program, in fact, an ABS () function is done. For example, you will be VB script, but the same program to replace the same Java script will be wrong, their data type is different, the syntax of the sentence is not the same. As in Chinese and foreign languages, the pronunciation of the mark (data type), how to pronounce (method), how to say a sentence (grammar) ... Oh, a little make you uncomfortable. Yes! Straight up. What you need to pay attention to in the future is the function and syntax of the language. Of course not to let you all look, follow the tutorial in the encounter a master. The tutorial finished, almost also finished. Oh, you have to believe me.

There are currently two main scripting languages: VBScript and JavaScript. Because VBScript is the default server script for IIS, what we're talking about is basically an ASP that is scripted around VBScript, and of course it doesn't rule out the use of JavaScript sometimes.

To give a very simple example:

<textarea class="bk" id="temp7453" rows="12"><script language= "VBScript" > <!--Sub Button1_onclick MsgBox ("Welcome to vbscript!") End Sub--> </script> <script language= "JavaScript" > <!--function b213 () {alert ("Welcome to javascript!" )}--> </script> <form> <input type= "button" Name= "Button1" value= "vbs" ><br> <input Type = "button" name= "Button2" value= "JS" onclick= "b213 ()" > </form> Sub in VBScript is an event procedure. The procedure name consists of two parts: a button name, Button1 (obtained from the Name property in the < INPUT > tag), and an event name, or OnClick. The two parts are connected by an underscore (_). When you click the button, Internet Explorer looks up and runs the appropriate event procedure, that is, Button1_onclick, and MsgBox is a function, and for its more specific parameters, you look good. </textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

On the spur of the moment, maybe everyone can see the internet a kind of crazy disgusting dialog box group, what is the principle? Please see:

<textarea class="bk" id="temp99167" rows="12"><script language= "VBScript" > MsgBox "You know you'll be a little bit sure .... "MsgBox" Not point also points ... "MsgBox" Is not a way to ...? "MsgBox" Or the webpage can't open ah ... "MsgBox" This trick is harmful to the ... "MsgBox" Really want to beat the webmaster ... </script> in fact, the webmaster use these to play with others, the first play with their own: because this is what he wanted to come out of AH: Oh, I did not damage everyone's meaning, just to learn. </textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

In the open page and page back pop-up dialog box principle
<textarea class="bk" id="temp77141" rows="12"><script language= "VBScript" > <!--Sub Window_onload () MsgBox "Welcome you!" End Sub sub Window_onunload () MS Gbox "See your late!" End Sub--> </script> open page display "Welcome you!", close page display "See You late! "</textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

Above is just a Display dialog Box MsgBox, and of course there are Writing dialog box InputBoxAnd by the way, look at it.

<textarea class="bk" id="temp97967" rows="12"><script language= "VBScript" > <!--Dim strname Strname=inputbox ("Enter your name please:", "Enter your name", "Cnbruce") document.write (strname& ", welcome you!<p>")--> </script> about InputBox The parameters also go and see. </textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

Let's look at a few more useful functions:
len (): Returns the length of a string or the byte length of a variable
lef (): Intercepts the contents of the first part of a string
Right (): Intercepts the latter part of a string
<textarea class="bk" id="temp79404" rows="12"><script language=vbs> text= "1234567890abcdefgh" i=10 lentext=len (text) lefttext=left (text,i) righttext= Right (text,i) alert (text length: &lentext) alert ("Text left &i&" is: "&lefttext") alert ("Text-Take &i&" Got is: "&righttext" </script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

According to these few, often see the long article after the "..." situation is as follows:

<textarea class="bk" id="temp61650" rows="12"><script language=vbs> text= "123 4567 8fds90 abcde fghxcfv" i=10 If Len (text) >i Then ' if the text length is greater than the given value Text=left (t ext,i) ' Extracts the I-bit string alert (text& "...") of the preceding paragraph else alert (text) End If </script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

There's a more important one. function replace ()
Finds in a string, substituting the specified string
Replace (Strtobesearched,strsearchfor,strreplacewith)
Strtobesearched is a string; strSearchFor is the substring being looked for; strReplaceWith is the substring to be substituted.
One of the following is a very useful text-to-speech program.
<textarea class="bk" id="temp88353" rows="12"><script language=vbs> text= "Damn it, I'll do It" text=replace (text, "Ma", "MD") text=replace (text, "Cao"), Alert (text) & Lt;/script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

Often in sending emails, add multiple addresses, the middle of the ";" to separate, that specific how to decompose a number of e-mail addresses received over it? Using the Split function: The Split function returns an array from the string.
<textarea class="bk" id="temp8243" rows="12"><script language=vbs> cnbruce= "cnbruce@126.com;cnbruce@it365cn.com;root@cnbruce.com" MyArray = Split ( Cnbruce, ";") A=myarray (0) B=myarray (1) c=myarray (2) alert (a) alert (b) alert (c) </script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

These are more realistic and better play, play in the study is also good: But after all, we have to program, to write programs, I know that the program structure can be divided into:
1, sequential structure:Is the most common, from the top down, from left to right to execute the program
2, select the structure:Give you two conditions, otherwise (if ... then), otherwise (else), you choose:
3, circular structure:Give you a maximum play space, do not go beyond this range of activities (loops), or automatically exit (out of the loop).
The complex procedure is nothing more than the three kinds of composite structure of the use of integrated nesting, you say it.

The sequence structure is not much to say, because program execution is basically in this direction.
To see the selection structure, of course, the selection structure can also be nested.

<textarea class="bk" id="temp75131" rows="12"><body> Hello, <script language= "VBScript" > <!--Dim thishour Thishour=hour (Time) if thishour<=12 Then document.bgcolor= "Red" document.fgcolor= "Black" document.write ("Good morning!"). else if Thishour<=18 then document.bgcolor= "Blue" document.fgcolor= "White" document.write ("Good afternoon!"). else document.bgcolor= "green" document.fgcolor= "yellow" document.write ("Good evening!"). ") End If--> </script> this page is to display different colors and welcome information at different times. </body></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

The above procedure is very simple, as long as can know English will understand the procedure (I understand so:)
The present hour is submitted first: hour (time);
Then and 12 compare judge, if <=12, must be morning, otherwise it is afternoon and evening;
Otherwise inside continue condition judgment, if time again <=18 words, that certainly is afternoon;
Finally, needless to say, the blind guess also knew that it was evening:

The Document.bgcolor in the previous program is the background color of the document, Document.fgcolor is the foreground color of the document (text color), and the next program changes the background color dynamically.

<textarea class="bk" id="temp74468" rows="12"><script language= "VBScript" > <!--sub Setbgcolor (bcolor) Document.bgcolor=bcolor End Sub--> </scrip t> <form> <input type= "Radio" name= "Color" onclick=setbgcolor ("Red") >red<br> <input type= " Radio "name=" "Color" onclick=setbgcolor ("green") >green<br> <input type= "Radio" name= "Color" onclick= Setbgcolor ("Blue") >blue<br> <input type= "Radio" name= "Color" onclick=setbgcolor ("yellow") >yellow <br> <input type= "Radio" name= "Color" Onclick=setbgcolor ("Gray") >gray<br> </form></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

About nesting of conditional selection structuresThen show a form detection program

<ptml><pead><title>abc</title> <script language= "VBScript" > <!--sub Btnsubmit_ onclick if form1.name.value<> "" Then If Form1.addr.value<> "" Then If Form1.email.value<> "" Then If InStr (Form1.email.value, "@") <>0 and InStr (Form1.email.value, ".") <>0 then Form1.submit else alert "email error!" End If Else alert "Enter your email!" Form1.elements ("email"). Focus End If Else alert "Enter your address!" Form1.elements ("addr"). Focus End If Else MsgBox "Enter your name please!" Form1.elements ("name"). Focus End If End Sub--> </script> </pead> <body> <form name= "Form1" Metho D=post action= "bug.html" > Your name:<input type= "text" name= "name" ><br> your addr:<input type= "text" Name= "Addr" ><br> your email:<input type= "text" name= "email" ><br> <input "button" type= " Btnsubmit "value=" "Submit" > </form> </body> </ptml>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

The program is given, but it seems more difficult to understand, and sometimes the program execution time is also more important, so you have to streamline the program code.
Is the so-called: easy to write procedures, write classic procedures difficult Ah, the above program can also be a way of thinking. Use JavaScript instead (note: Learn programming ideas, don't be too fussy about script types)

<textarea class="bk" id="temp23602" rows="12"><ptml><pead><title>abc</title> <script language= "JavaScript" > <!--function Form1_onsubmit () {if (document.form1.name.value== "") {alert ("Please set your login name.") ") Document.form1.name.focus () return false} else if (document.form1.addr.value==" ") {alert (" Please fill in your address. ") ") Document.form1.addr.focus () return false} else if (document.form1.email.value==" ") {alert (" Please fill in your e-mail Access. ") Document.form1.email.focus () return False}}--> </script> </pead> <body> <form name= "Form1" onsubmit= "Return Form1_onsubmit ()" > Your name:<input type= "text" name= "name" ><br> your addr: <input type= "text" name= "addr" ><br> your email:<input type= "text" name= "email" ><br> <input Type= "Submit" name= "submit" value= "Submit" > </form> </body> </ptml></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]


Finally, look at the Loop StructureBar: 1 to 500 is not written by one.

<textarea class="bk" id="temp75940" rows="12"><script language=vbs> for i= 1 to document.write (i& "<br>") Next </script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

Of course, the loop can not only use for, but also with do while...loop and so on
Anyway the program this thing is instead of us doing a lot of repetition of a single boring thing-as long as you make reasonable use of the program.

Should have some achievements, learning language, learning programming is to learn grammatical semantics, learning programming architecture ideas.
Of course, this should you have a solid foundation of the language, what is the basis? You know what functionDo you? Do you know how to use a program to determine an even number (including Operation)? Do you know how to perform form detection? Do you know any of the three program architectures?

Functions refer to:
http://www.cnbruce.com/blog/showlog.asp?cat_id=26&log_id=245

Oh, the above procedures thoroughly, it is best to look at the script reference manual, and I can start ASP's on the road.

Fill

A Function procedure is similar to a Sub procedure, but a Function procedure can return a value.
A Function procedure can also use a constant, variable, or expression passed by the calling procedure as a parameter. If the Function procedure has no arguments, the function statement must contain parentheses ().
A Function procedure returns a value that is assigned to a function name in the statement of a procedure by its name. The data type of a function return value is always a Variant.
Related Article

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.