Use subroutines and functions
Author: Qing Apple Computer Studio Click: 351
A question about quickly: Why are there so little about the code of using subroutines and functions in the book of ASP?
Although it is easier to write ASP code and line by line, it has many benefits to encoding in the form of a program.
First of all, non -programmatic code is not easy to port to Visual Basic. Maybe you don't have this plan at present, but one day you will do it for one day
Its performance or scalability is transplanted into components.
The second is that the program is running faster. The maximum consumption of ASP performance is the context conversion.
HTML will happen when. Because you will not change a context in the program, you will feel this consumption. Also, ASP
The buffer also shows that when the subroutine uses a programmatic code to click on the page, it will be very different. This is an ASP application using a programmatic code
The necessary part of Hello World:
Prive Sub Main ()
Response.write Hello World!
end sub
call major
For complete reasons, I contain a small example of context conversion in the program. If you test this code, it will run, but please
Don't do this inside your own application.
< %@ Language = VBScript %>
< %
Private sub dostuff ()
%>
this is <b> html text! < /b>
< %
end sub
%>
<html>
<head>
<meta name = Generator Content = Microsoft Visual Studio 6.0>
< /head>
<body>
<p> < % call dostuff %> < /p>
< /body>
< /html>
There are some other benefits of the programmatic code. First of all, you will find that it is easier to use the code part included in the program. Second, want
There are fewer code lines required for the same purpose. Third, you will start developing a large repayable code library. Starting it
The form is .inc file. Finally, your own ordinary COM component looks as good as Jeff Gordon (famous racing player).
Transplant your code
There are several things as simple as transplanted from VBSCRIPT to Visual Basic. Generally speaking, you need to remove the code and add the data type.
Sometimes, some more effective algorithms can also be applied in Visual Basic, but you must ensure that the code can work normally.
In our application for example, some simple code will be transplanted to two Visual Basic COM components. Will some html
The format format is dragged into the expression class, and the ADO object code is dragged into the data access class that wraps ADO. By put these two classes in
The Activex DLL engineering file can make the project file a little simplify. In actual work, a separate project can be created for each level
Files, but this engineering file shows ideas in a DLL. If you want to correct this situation, move the data access class to another
In the engineering file, it is compiled as a DLL. Must be applied to this new DLL reference to the DLL engineering file to be applied.
The database used in this sample engineering file is a Northwind database that is included with Visual Basic. In this
In the Zip file of the sample engineering file, I made a version of this file for those who did not install Visual Basic. sample
The engineering file also contains a compiled DLL compiled with ASP code.