ASP forced declaration variable

zhaozj2021-02-16  123

Unlike C or other languages, using variables in VBScript is not required to be defined in advance. You can use a new variable name anytime, anywhere, as long as you don't repeat it, and you will not conflict with the reserved word!

This may be very convenient, but ... you see the following program code:

<%

myfirstvariable = 2

Response.write "Variable MyfirstVariable value is:"

Response.write myfirtvariable

%>

What is the result of output? Of course, it will not be "2". Let's take a look at the fourth line of the program, and the name of the variable is missing!

Don't laugh, this is a mistake that everyone may commit (if you are still on the computer, there is a large pile of dense linen procedures in front of the computer ...).

To avoid such errors, and make the program easier to find such errors when performing degne, as long as you add the following line below:

<% OPTION Explicit%>

In this way, VBScript will force us to make a declaration of the variable to use, otherwise the runtime error error message will appear.

Like this below:

<% OPTION Explicit%>

<%

DIM MyFirstvariable

Myfirstvariable = 2 response.write "Variable MyfirstVariable value is:" Response.write myfirtvariable

%>

Even if you play a wrong word, there will be an error message when you execute, tell us which line is problem, help us in the wrong.

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

New Post(0)