Problem | Experience posted from: http://www.5d.cn/bbs/NewsDetail.asp?id=917831
1. Omit Dim, convenient but also hidden trouble!
application variables are standard methods:
Dim a
a = "1"
In fact, you can not write Dim also:
a = "1"
system does not think that error, it will automatically determine whether a is an existing variable, the existence will continue to execute, if it does not exist automatically to help you apply! It seems that the system is smart and smart and thoughtful, but the hidden trouble comes out! Does the system know what I mean? The system is likely to be a smart-aleck, kind of counterproductive! Question one: If I have already applied for a variable, such as the administrator, I want to give the variable value, I unfortunately wrote a wrong letter or less write a letter, such as Administratar = "Me", the system finally wait for a " Help "My chance, and" volunteered "for me to declare variables," thoughtful "unspeakable! Yes, the program may run, but logically it has become a mess, because the system does not report an error (or a different error to mislead you), you can not quickly locate the problem, if the program is very large, you spend a lot of time to find the root cause, how do you feel? You must want to scold the system "self-made amorous", if the system reported a Administratar variable name does not exist, I will soon be able to know that their spelling is wrong, and the problem quickly corrected, and do not have to "indulge" in the system of "self-made amorous" among! Omitting the dim after another hidden trouble will be said later!
2. Variables declared within the function do not interfere with external variables!
For example:
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%
Dim a
a = "1"
function getstr ()
Dim a
a = "2"
End Function
Response. Write A & "<br>"
getstr ()
Response. Write A & "<br>"
%>
results show that the variables declared inside the function will not interfere with the outside, its scope is the function inside, in fact, learn other languages should know! But first of all, if you remove the dim a In the function, then take that a as an external a, and the result will change! File inside the application variable, his scope is this file.
3. A include! of love and Hate
include makes the ASP program more structured, and some commonly used functions can be shared by other files! He brings the benefits at the same time you must pay attention to shortcomings!
now goes back to the 1th talk about omitting dim, which is what I assigned to the system "kindness" into a declaration variable. Now, on the contrary, I want to declare variables, the system is assigned a value, because omitting dim can also declare variables, for those who can save the province like streamlining programmers, often block this temptation (I sometimes like to apply, hehe) but can you guarantee that the variable name you are applying for is not in the previous program? If you have this variable name in front of you, then you are not applying for an assignment? The same file may rarely make this mistake, but don't forget include, he is included in the file, if included in the file with the variable you apply, then you are finished, even if it can run, logically is already problematic. If you are not lazy, with Dim application, the error, you are lucky to know that the variable name already exists! It will be corrected soon!
Now to discuss more complex situation, if you include two files in, all of these two files have the same variable name, if two are using Dim application, fortunately, just the error, said the variable name already exists, soon can know the problem. Now you can understand why I'm talking about the 2nd scope, because of the scope, different files with the same name variable will generally not "fight". However, if you are included in another file, the problem is troublesome, so if you write an ASP file that is intended to be contained, prevent the occurrence of the same name. And then back to the original discussion, if the two include files in the application of the same name variables are dim okay, but the following include file is used to omit dim application, the problem comes, the following omitted dim application into the assignment, the fatal is, this is in two include files, very covert, find the problem more difficult!
To sum up, we can write some simple examples to realize the problem, the final recommendation:
1. Variable please use Dim to apply for reuse first! Especially the complex programs developed by many people!
2. Assign a value to a variable please note the variable spelling!
3. Carefully understand the file include.
* * * now talk about error:
in fact, finding problems is more important than code writing! My personal experience, the problem is divided into three categories:
1. Error class, compile system in the process of compiling the system encountered problems, it will give error messages, this is the programmer's favorite problem, oh, not abnormal, but this problem to check up the simplest!
2. Logical class, more annoying problem, the program compiles successfully, also can run, but the result that displays is not the result that you expect in logic. Oh, my god! How to do, no hint of information, can only rely on experience and feelings to analyze the results of the error, and then check the source code, smooth words, a few minutes to solve, a difficult day down also no results!
3. Performance class, very terrible problem, the program compiles successfully, also can run normally, show also normal! However, occasionally a time to make a mistake, you do not know what the circumstances of the error is triggered, or the program performance is not as high as similar programs, running slowly, these problems, some one weeks one months can be solved, and some almost is a stubborn disease, not cured. I have been this kind of problem toss and die!
So, to learn to program, we must try to solve their own problems, especially like the ASP program, the logic of the problem is not the case, out of the basic problems are errors, error information, error location, analysis of their own analysis should not be difficult to solve. I think some people are willing to spend three days on the forum to wait for others to tell their own questions, why not solve them? Find yourself a problem, a long experience, this is the wealth of programmers!
* * * A little Programmer's experience:
don't think you can write a few lines of code, do a few small programs are thought to be programmers, when you go to the software company for a few years you will understand what is called a programmer, write code is not what, code error, optimize the code, writing software document (not a simple user manual, but a project application, project preliminary design instructions, Project Detail design book, Database design specification, project test Manual, user manual, user maintenance manual, etc., in fact, you will program, does not mean that you can develop software. In fact, I still do not good enough in some aspects, such as writing software documents, hehe, think it is a very scary thing, writing software documents more painful than writing procedures! I did three years of Delphi programmers, although leaving the company when the completion of a good software project. But still feel oneself insufficient, so now I still complement all other aspects of technology, this social competition has been very intense, you do not work hard upwards, the more you strive to close to unemployment!
for the first question, I strongly recommend that you define it in dim before you use it, and it's not very difficult to write one more line of code. Then in the ASP file head with <%option Explicit%>, so that if you accidentally write the variable name wrong, it will return the variable does not define the error, you can easily detect the wrong location, otherwise, the variable is a null value.
In addition, combine option Explicit to say a second question. Sometimes we need to include multiple files (such as head definition, top navigation, and so on), and Option Explicit in an ASP application (note that here is application, especially one application, not page, Does not represent a page) can only be used once. Therefore, Option explicit should not be placed inside the include file in order to avoid being confused by multiple pages of calls.
a little question about include. Generally, if you need to include the file in the current directory, we can directly use the
<!--#include file= "abc.asp"-->
to contain it. However, many times we have n files that need to be included. So, for ease of management, we put them together in an Inc or include directory. In this way, sometimes the code is written:
<!--#include file= ". \inc\abc.asp "-->
This is the question I want to discuss. Please note that using the. Access to the top-level directory, which poses a security risk: users may illegally refer to the site's external files. For this reason, the Microsoft-published IIS lockdown Tool Masks This referral method, and Microsoft is blocked by default on Windows Server 2003 IIS6.0. This safe reference method is recommended for this inclusion file that is not in this directory:
<!--#include virtual= "/inc/abc.asp"-->
welcome more useful exploration and discussion