Use ASP script technology

xiaoxiao2021-03-05  22

In the VB script, you don't have to define variables or identify their types in other scripting languages. A variable exists when you first use it. However, this feature allows your code to exist in typing. If you define a variable name in your code, then a new variable will be created. Your script may not work properly, and you may not be able to realize this error.

Transfer from: Dynamic Network Production Guide www.knowsky.com

When you use the variable, you have to develop their habits, what you need to do is to test DIM VARIABLENAME:

% <% DIM INTUSERID%>%

INTUSERID can now be used. For another security net, use Option Explicit. If you open Option Explicit, you will issue an error in any time using the variable. This sounds are very boring, but when your script is wrong, he can give you some clues, otherwise you have to find out the error.

In order to use Option Explicit, the following content will be used as the first line of your script:

<% OPTION Explicit%>

If you want to see what happens when you forget to define a variable, you can run the following code:

<% OPTION Explicit%> <:% strname = request.form ("name")%>

Because the strname variable (DIM STRNAME) is not defined, you will see what happens below:

Microsoft VBScript Runtime Error '800A01F4'variable is undefined:' strname '/ e / oe-test.asp, line 10

Using LEN You can use the Len (String) function to determine the length of the string of the text:

<% IntString = ". This is a Simple Sentence" IntStringLength = Len (IntString) Response.Write "There are" & IntStringLength & "characters (including spaces) in the sentence shown below:" Response.Write "" & IntString & " "%>

If you want to know how Len works manually, you can think of you asking users to enter their five-digit code or three PIN forms. With Len, your papers have entered enough numbers.

Use the TrimtrimMing string to be something you want to get at the beginning. Many times, a string has an extra space at the beginning or end, if you don't balance it, you may worry about waste time to these variables.

<% StrName = Request.Form ( "Name") strCheckName = "Amy Cowen" If strName = strCheckName THENResponse.Write "Success! The names matched." ElseResponse.Write "Sorry. The names do not match." End if%>

If the value of Strname is "Amy Cowen", because that is how I entered it into form box, then test whether the two variables are the same, the result is not, because "Amy Cowen" is not "Amy Cowen." The same, if you Enter the NAME into the URL:

<% Response.write "& objrec (" name ") &"> your "%>

If any part of the record in Name has additional space, you will perform the error problem quickly.

You can correct the entire string on the left or right side:

<% strcomments = request.form ("comments") STRCOMMENTS = Trim (STRCOMMENTS)%>

Suppose users have entered ::

"I am Having Problems Installing The Software I Downloaded."

The above trim statement will disperse additional space, leaving only the following:

"I am Having Problems Installing The Software I Downloaded."

Now, return to our "Amy Cowen" example, if I add the following script, we will succeed:

Strname = trim (strname)

Trim on the right, use RTRIM (String). Trimped on the left and use Ltrim (String).

Conversion When you start using and VB almost a language, you will make some simple errors, such as comparing intellectual 512 and string 512. If you realize that the previous 512 and the latter 512 are different, you can think about why the script given is not working properly.

If you send a file ID to the ASP script, use Request.QueryString, you will determine the ID of this file is the user wants to edit. You need to enter some information from the database and display them on the screen. The ID and integer in the database are similar, especially if you use Autonumber performance in that area. The id you entered is actually a string. Therefore, these two will never match unless you convert to the same type.

Request.QueryString: Using FileSystemObject, you can test a text, for example, * .html, * .asp, * .inc., * .Gif- or directory. If the file exists, you can want a series of time. If the file does not exist, you may need other events, using the following code: <% spath = "/ profiles /" & strfilename & ".asp" sfile = server.mappath (spath) set fe = server.createObject (" Scripting.filesystemObject ") if fe.fileexists (sfile) Then 'do something "write" yeah! I found it !. "Response.write" You can access what file by "response.write" Clicking Here ." Else 'Do Something Response.write "sorry. The Requested File Does Not%> For simple testing your file, add a script to the top :

strFileName = "name" 'First assign the name of a file you have to this variable.' strFileName holds just the name, not the extension or the path. 'Make sure you change the path for sPath to the virtual directory your file is in 'Run the script.' The com back and change the strfilename variable to the name of a file 'you do not there.' Run the script.

Changing the code entered is very easy and allows you to make your future work easier, the sample format is like this:

<% DIM INTUSERID INTUSERID = Request.QueryString ("UserID") INTUSERID = CINT (intuserid) 'Intuserid is now an integer.%>

You can also comment your ASP code and use them.

Comment Code In ASP, a script is executed before it is sent to the browser, so you don't need to use a normal HTML annotation tag to hide the script from the old browser. In fact, your script will not be displayed in the HTML source, because the source code is handed out by the browser, so the old browser does not suddenly transmit any code to the screen.

You may want to comment to comment your ASP script, in the VB script, you can use the illegal compute to record the comment:

<% currentdate = now

'Make Sure You Use Quotation Marks Around The Html Code' The & Serves To Concatenate The StringResponse.write "Today IS:" & Currentdate & "
"

%>

Use // in the ASP script to indicate comments

Using the included if you have used it .shtml file, you may be familiar with the included work process, if not, let's tell you step by step.

A containing capacity, which is stored in a separate file. In standard HTML, it contains usually used .inc extensions. In ASP, you use .asp, .txt or .inc extension. Then you will call the file into the HTML code. When the HTML file is sent, the content containing files from a special file and writes directly to the screen as HTML. So if you make a view source code, what you see is the same effect as you entered.

For a normal HTML, when you create a template for the site, it saves a lot of time. Head, footer and navigation elements are part of the display in your large number of pages. When you use it, you have to enter a file once and call it when you need it. There are several advantages:

When updating content, you only need to update a file. Contains MEAT is isolated from the HTML page, so anyone wants to modify the content to avoid messages. Your core HTML file smaller and more practical. In ASP, it is incurable. You can use scripts over and over again, even sometimes like a connection string is stored in an inclusion, and it can be deleted in an unused page.

In order to use the included file, you use any of these formats:

or

.

The file reference contains the path to use. Virtual references an absolute path to related servers. If you want to move catalogs and files, the easiest way is to use Virtual by default, so that you will not encounter some unexpected errors. On the other hand, when you test the file, you need to use the file because he rely on how you set the personal server.

In the standard HTML, you usually give you the containment file. Infix. In ASP, you can use .asp. This can prevent your files from open and read others.

转载请注明原文地址:https://www.9cbs.com/read-36259.html

New Post(0)