home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
vb_refer
/
loadtime
/
loadti.txt
Wrap
Text File
|
1991-11-21
|
3KB
|
55 lines
Visual Basic: Load time problem solution.
When a Visual Basic application is launched, the mouse cursor is
changed to hourglass mode. Unfortunately, the cursor reverts back to
the arrow pointer long before the application is loaded. The load time of
a VB application is effected by the number of objects which are placed on
the designated Startup form and the code associated with the objects. A
user may become confused about the state of the application and double
click it's icon again causing additional instances of the application to
be launched. This problem is far more evident on slower machines.
Fortunately, the cause of the problem can be implemented as the solution.
Simply create a small "banner" form as the Startup form. This form should
contain only two objects; a label with a caption telling the user to wait
while the program loads (Label1) and a timer (Timer1). The properties for
the form are all defaults except for the following: ControlBox = False;
MaxButton = False, MinButton = False; BorderStyle = 0 - None. The Timer is
enabled with an interval of 1. For best effect, dimension the form to
match the size of Label1. Listed below are the subroutines associated with
the banner form. The Form_Load procedure will complete before the Timer1_Timer
event is invoked.
Sub Form_Load ()
Screen.MousePointer = 11 ' Hourglass cursor
Banner.Left = (Screen.Width - Banner.Width) / 2 ' Center message Left/Right
Banner.Top = (Screen.Height - Banner.Height) / 2 ' Center message Top/Bottom
End Sub
Sub Timer1_Timer ()
Timer1.Enabled = 0 ' False - Turn off the timer
Load MainForm ' Load form with Visible Property set to False
MainForm.Visible = -1 ' True - Keep it hidden until the load is complete
End Sub
In the main form, the only housekeeping that needs to be done to
conclude this technic is unloading of the Startup form and resetting the
mouse.
Sub Form_Load ()
..... do miscellaneous housekeeping and setup routines here .....
Unload Banner ' Eliminate user's message
Screen.MousePointer = 0 ' set to normal Arrow Pointer
End Sub
Using these routines will keep the mouse as an hourglass for most of the
time required to launch the program. Use Banner.Label1.Caption to provide
additional status reports to the user for applications which perform
extensive operations prior to releasing control to the user. Use
Banner.Label1.Refresh to get the message out promptly.
An additional method for improving loading speed is to use the MainForm strictly as the
application's menu. Only the code for loading other forms should be placed in the
MainForm. Using small, single purpose forms will keep overall coding simpler and more
readable.