Visual Basic as an advanced programming language, which also has inevitable shortcomings - the development of the developed application is slow. If we can make some optimization, then the situation will greatly improve. To optimize the actual speed of the program, there are three common methods:
1. Try to avoid using a Variant variable. Since VB cannot determine the specific type of Variant variable, it assigns 16 bytes of space to this type variable, and the conversion of the data type is considered when calculating with variables. This takes up both memory and affects the speed, which will make the program involved in complex operations slow. Note that the default type of a variable is Variant, and other types of variables must be declared separately with a DIM statement.
2. Try to use the long variable as much as possible when you encounter integer data. Because the long variable is the 32-bit CPU native data type, the processing speed will be very fast, especially in the circulation body.
3. Save the common properties of the control in the variable. The general control is present in an external program of the DLL or OCX. It is well known that calling DLL is much longer than access. So for those common attributes placed in the cyclic body, if they are saved in the variable, then there will be hundreds of times the speed.
We should notice that when writing a program, we can do some animations such as working for a long time, so that users know that the program is operating normally. Below is a few common optimization methods:
(1)
Use the Splash screen. That is, our common welcome window. When the big application is started, it tends to load a lot of DLL active or passively, which takes a long time. So we can first display a simple window at startup. Only some author, copyright, etc., use the LOAD method in the Form_Load event in this window to read those most commonly used form modules. Thus, although the actual waiting time is extended, the screen that the user has seen always changes, so it feels that the program starts up. Moreover, since the common form module has been loaded in advance, simply use the Show method to display it, skip the load process, which will be fast during the program run.
(2)
Use the Timer control. Due to the emergence of the Timer control, it has possible background jobs. We can complete a small part of the task in each Timer event. Thus, since the event in Timer can be completed in a short period of time, the user generally misses the speed change. If you have to complete a task in a loop, don't forget to use Doevents to release the user.
(3)
Use the progress bar. To use the progress bar, you need to know the amount of data in advance, so it is well suited for the operation of known data, such as the database.
In short, the optimization procedure should be considered from ourselves, from users, so that the program development cycle is shorter, and is efficient.