I saw some friends saying that the previous chapter was unnecessary, and it’s true when I think about it. I didn’t originally intend to talk about these basics, but there was no restriction on the writing, so I just moved on to the basic knowledge. Starting from this section, I will give Let me introduce some of the three major general classes in ASP. They run through the three-tier architecture I designed. They are an extension of ASP syntax and can improve the efficiency of processing many details. They can be regarded as a little bit of a framework.
This section introduces the error handling class. The class name is Con_Error. It is initialized at the beginning of the code page. The instance name is e. The following e.add uses the instantiated object of this error class to operate.
Method introduction:
e.Add(ByVal vErrorMessage) records an error and sets e.Error = true. When an error is found when the program checks the validity of the user name, etc., this method is called and an error message is recorded.
For example, if the user has an incorrect password when logging in, call e.add (your account or password is incorrect). At this time, an error is recorded in the error object e, and the attribute of the error object e.Error=true. In subsequent operations, You can use this property of the error object to make a judgment.
For example:
When an error occurs, a small window will pop up to prompt the error and return to the previous page.
if e.Error then
e.Alert_Back Please log in again! 'The function of Alert_Back will be introduced later.
end if
e.Alert_Back(ByVal vMessage) uses Javascript to pop up an error prompt box and displays a list of all current errors. The vMessage in Alert_Back(vMessage) is displayed on the last line to prompt the user on the steps to take after seeing this error message. And return to the previous page. Post the code of this method so that everyone can understand it better:
Public Sub Alert_Back(ByVal vMessage)
strJSMessage = JSMessage & vMessage 'JSMessage is used to store the error list in the e object, and each error is separated by /n.
%>
<script language=javascript>
<!--//
alert(<%=strJSMessage %>); 'Pop up an error box.
history.back(); 'Return to the previous page
//-->
</script>
<%
response.end 'Note that the output should be stopped here to avoid errors while the program continues to execute.
End Sub
The e.Alert_Back method extends several methods with similar effects, which are introduced below. Please see the attached source code for the implementation process:
e.Alert(ByVal vMessage) only pops up an error prompt box, does not return to the previous page, and does not stop the execution of the program.
e.Alert_Close(ByVal vMessage) pops up an error prompt box. When the user clicks OK, close the current window.
e.OK_Go(ByVal vMessage,ByVal vURL) pops up a message prompt box. When the user clicks OK, it jumps to the vURL page.
e.Go(ByVal vURL) Jump directly to the vURL page
Everyone should be familiar with the functions of the above methods, but in fact they are not limited to error handling.
e.Clear clears the error information recorded in the error object, e.Error = false
Because the e object is a global object, it may be called in many processes. When you only need to count errors in a certain module, you can call this method at the beginning to clear the errors in e.
The following are packages for Response.Write, just for the convenience and speed of use.
e.Debug(ByVal vMessage) outputs debugging information. When the program is completed, there will be a lot of error debugging information output using Response.write. You have to delete them all and look for them carefully. Use e.Debug to specifically output debugging information. , when the program is completed, you only need to search for e.Debug to find the location of all debugging error information.
ew(ByVal vMessage) outputs information. It is just a simple wrapper of Response.write. It is not known how much more convenient it is to enter ew in the program than to enter Response.write, and it is always easy to make mistakes.
e.BR outputs a newline character, which is equivalent to response.Write <BR />
The following four are packages for Response.End. They are just several methods with the same functions defined according to operating habits:
e.Pause == Response.End
eP==Response.End
e.Stop == Response.End
e.End == Response.End
There is also an attribute e.Message, which outputs a list of all errors in the e object.
Please see the code for specific implementation details.
Copy the code code as follows:
ClassCon_Error
PrivateblnError
private strMessage
private strJSMessage
Private Sub Class_initialize()
blnError = false
strMessage =
End Sub
Private Sub Class_Terminate()
End Sub
' ================================================= =================================
' Property
' ================================================= =================================
'Message:
Public Property Let Message(ByVal value)
strMessage = value
End Property
Public Property Get Message()
Message = strMessage
End Property
'Error number
Public Property GetError()
Error = blnError
End Property
' JSMessage: show in messagebox
Private Property GetJSMessage()
strJSMessage = Replace(strMessage, <br>, /n)
strJSMessage = Replace(strJSMessage, vbCrLf,)
JSMessage = strJSMessage
End Property
' ================================================= =================================
'Method
' ================================================= =================================
' Add : add an Error message
Public Sub Add(ByVal vMessage)
blnError = true
strMessage = strMessage & vMessage & <br>
End Sub
Public Sub Clear
blnError = false
strMessage =
End Sub
'Alert
Public Sub Alert(ByVal vMessage)
strJSMessage = JSMessage & vMessage
%>
<script language=javascript>
<!--//
alert(<%=strJSMessage %>);
//-->
</script>
<%
End Sub
' Alert_Back : alert and back
Public Sub Alert_Back(ByVal vMessage)
strJSMessage = JSMessage & vMessage
%>
<script language=javascript>
<!--//
alert(<%=strJSMessage %>);
history.back();
//-->
</script>
<%
response.end
End Sub
'Alert_Close: alert and close
Public Sub Alert_Close(ByVal vMessage)
strJSMessage = JSMessage & vMessage
%>
<script language=javascript>
<!--//
alert(<%=strJSMessage %>);
window.opener = null;
window.close();
//-->
</script>
<%
response.end
End Sub
'************************************************
'Debug : response.write ,use it to delete debug message easily,just search e.Debug from files
'************************************************
Public Sub OK_Go(ByVal vMessage,ByVal vURL)
strJSMessage = JSMessage & vMessage
%>
<script language=javascript>
<!--//
alert(<%=strJSMessage %>);
location.href = '<%=vURL %>';
//-->
</script>
<%
response.end
End Sub
Public Sub Go(ByVal vURL)
response.Redirect vURL
response.end
End Sub
'************************************************
'Debug : response.write ,use it to delete debug message easily,just search e.Debug from files
'************************************************
Public Sub Debug (ByVal vMessage)
response.Write vMessage
response.flush
End Sub
'****** W: write
Public Sub W(ByVal vMessage)
response.Write vMessage
End Sub
'****** BR: write <br>
Public Sub Br
response.Write <BR />
End Sub
'************************************************
'Pause: response.end, mark debug info clearly
'************************************************
Public Sub Pause
response.end
End Sub
Public Sub P
response.end
End Sub
Public Sub [Stop]
response.end
End Sub
Public Sub [end]
response.end
End Sub
End Class