Through the first two articles,I believe you already have a basic concept and overall impression of ASP's dynamic website design.From this article the author will start with the use of scripting language,From shallow to deep, we will lead you to explore the true secrets of asp dynamic website design.
Now I would like to invite you to follow me to learn some basic knowledge of application scripting language (mainly vbscript) in ASP.
Before you start learning scripting languages,You should understand some simple concepts-variables, processes. A variable is a named storage location in the computer's memory.It contains data such as numbers or strings.It makes it easy for users to understand the names of script actions,Provides a way for users to store, retrieve, and manipulate data.A program is made up of one or more processes.In vbscript, a process is an "instruction block", a process in the usual sense,Such as sub, just for simple data processing.
VIn vbscript, strictly speaking, variables are not declared,
<%mystring="this is my string"%>
However, even if you do not need to declare variables before using them,You should also develop a good habit of declaring variables when programming,Because this helps prevent errors.Declaring a variable means telling the script engine,A variable with a specific name,This allows you to reference the variable in the script.To declare a variable in vbscript, use the "dim" statement, as follows:
<script language="vbscript"> <!- Option explicit "requires all variables to be declared in the script Dim mystring String mystring="this is my string" -> </script>
The scope of a martingale variable is its lifetime,Decide which script commands can access variables.Variables declared inside a procedure have local scope.Every time the process is executed,The variable is created and then dies.It cannot be accessed by any command outside the procedure.Variables declared outside a procedure have global scope,Its value can be accessed and modified by any script command on the asp page.When declaring variables,Local and global variables can have the same name.Changing the value of one does not change the value of the other.If no variables are declared,You may accidentally change the value of a global variable.For example, the following script command returns the value 1, although there are two variables named y:
<% Dim yy=1call setlocalvariableresponse.write y Sub setlocalvariable Dim y Y=2end sub%＞
Since the variable is not explicitly declared,The following script command returns 2. When the procedure call sets y to 2, the script engine considers the procedure to modify a global variable:
<% Y=1call setlocalvariableresponse.write y Sub setlocalvariable Y=2 End sub%＞
However, global variables are only available in a single ASP page,To make it available outside a single ASP page,Variables must be scoped to the session or application.Session-scoped variables are available to all pages in an ASP application requested by a user.The same is true for application scope variables.For a single user,Session variables are the best way to store information.For example, user preference, user name, or user's identity.For all users of a particular application,Application scope is the best way to store information,For example, application-specific greetings or initial values required by the application.asp provides two built-in objects to let you store variables:a session object and an application object, which will be discussed in the future asp built-in objects.
Let's look at the definition of constants again.Constants are names used in place of a number or string.It stays the same throughout the script.You can use the const statement to create user-defined constants in vbscript.Use const statements to create string or numeric constants with meaningful names.And assign them literal values.E.g:.
Example:<%const mystring="This is a constant"%>
note Note that string literals are enclosed between two quotation marks (""). This is the most obvious way to distinguish string constants from numeric constants.Date text and time text are enclosed between two pound signs (#). E.g:
<%const cutoffdate=#6-1-97 #%>
After understanding constants and variables,Let's see what is the process.It is a set of script commands that perform a specified task and have a return value.You can define your own process,Then call them repeatedly in the script.You can place the procedure definition in the .asp file that calls the procedure, or you can place the common procedure in a shared .asp file, and then use the ssi #include directive to include it in other .asp files that call its procedure. You can also choose another method,These functions are packaged in activex components. Process definitions can appear inside thetags and must follow the rules for declaring a scripting language.If the language of the procedure is different from the main scripting language,Then use the<script>element. Procedures in the main scripting language are separated by script delimiters (<%and%>). When tagging with html
The runat=server attribute here tells the web server to process the script on the server.If this property is not set,The script will be processed by the client browser.The language attribute determines the scripting language used by this script block.You can specify any language with a scripting engine.Use vbscript to specify vbscript;use jscript to specify jscript. If the language property is not set, this script block is interpreted in the main scripting language.
VIn vbscript, procedures are divided into two categories:sub procedures and function procedures. A sub procedure is a set of vbscript statements contained between sub and end sub statements that perform an operation but return no value.The sub procedure can take parameters (constants, variables, or expressions passed by the calling procedure). If the sub procedure has no parameters,The sub statement must contain empty parentheses ().
A function procedure is a set of vbscript statements contained between a function and an end function statement. The function procedure is similar to the sub procedure,But the function procedure can return a value.The function procedure can take parameters (constants, variables, or expressions passed by the calling procedure). If the function procedure has no parameters,The function statement must contain empty parentheses (). The function procedure returns a value by function name,This value is assigned to the function name in the statement of the procedure.The data type of the function return value is always variant. In the following example, the sub procedure uses two inherent (or built-in) vbscript functions, msgbox and inputbox, to prompt the user for information.The results calculated based on this information are then displayed.The calculation is done by a function procedure created using vbscript,The celsius function converts degrees Fahrenheit to degrees Celsius.When the sub procedure converttemp calls this function,Variables containing parameter values are passed to the function.The conversion result is returned to the calling procedure and displayed in a message box.
sub converttemp () Temp=inputbox ("Please enter Fahrenheit. ", 1) Msgbox "Temperature is"&celsius (temp)&"Celsius." End sub Function celsius (fdegrees) Celsius=(fdegrees-32) * 5/9 End function
The way to pass data to a process is to use parameters.Parameters are used as placeholders for the data to be passed to the procedure.The parameter name can be any valid variable name.When you create a procedure using a sub statement or a function statement,The procedure name must be immediately followed by parentheses.All parameters are in parentheses,Parameters are separated by commas.For example, in the following example,fdegrees is a placeholder for the value passed to the celsius function:
function celsius (fdegrees) Celsius=(fdegrees-32) * 5/9 End function
To get data from the process,You must use the function procedure. Remember that the function procedure can return a value;The sub procedure does not return a value.
The above briefly introduces vbscript to everyone. Due to space reasons,It's impossible to go into all the details of vbscript here.But since ASP is not a programming language in itself,So in the process of writing asp applications,Many special functions must be implemented with the help of a scripting language,So flexible and proficient in scripting languages is essential for a programmer writing web applications using asp.
Whether you are an experienced programmer or a beginner,As long as you now want to write a web application via asp,We highly recommend that you master at least one scripting language (such as vbscript).
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file