home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_refer / loadtime / loadti.txt
Text File  |  1991-11-21  |  3KB  |  55 lines

  1. Visual Basic:  Load time problem solution. 
  2.  
  3. When a Visual Basic application is launched, the mouse cursor is 
  4. changed to hourglass mode.   Unfortunately,  the  cursor reverts back to 
  5. the arrow pointer long before the application is loaded.  The load time of
  6. a VB application is effected by the number of objects which are placed on 
  7. the designated Startup form and the code associated with the objects.   A
  8. user may  become confused about the state of the application and double 
  9. click it's icon again causing additional instances of the application to
  10. be launched.   This problem is far more evident on slower machines.    
  11.  
  12. Fortunately, the cause of the problem can be implemented as the solution.  
  13. Simply create a small "banner" form as the Startup form.  This form should 
  14. contain only two objects; a label with a caption telling the user to wait 
  15. while the program loads (Label1) and a timer (Timer1).  The properties for 
  16. the form are all defaults except for the following: ControlBox = False; 
  17. MaxButton = False, MinButton = False; BorderStyle = 0 - None.  The Timer is
  18. enabled with an interval of 1.  For best effect, dimension the form to 
  19. match the size of Label1.  Listed below are the subroutines associated with
  20. the banner form.  The Form_Load procedure will complete before the Timer1_Timer
  21. event is invoked.   
  22.  
  23. Sub Form_Load () 
  24.     Screen.MousePointer = 11     '  Hourglass cursor 
  25.     Banner.Left = (Screen.Width - Banner.Width) / 2        '  Center message Left/Right 
  26.     Banner.Top = (Screen.Height - Banner.Height) / 2      '  Center message Top/Bottom 
  27.  End Sub 
  28.  
  29. Sub Timer1_Timer () 
  30.     Timer1.Enabled = 0           '  False   -   Turn off the timer  
  31.     Load MainForm                 '   Load form with Visible Property set to False 
  32.     MainForm.Visible = -1       '  True  -  Keep it hidden until the load is complete 
  33. End Sub 
  34.  
  35. In the main form, the only housekeeping that needs to be done to
  36. conclude this technic is unloading of the Startup form and resetting the
  37. mouse. 
  38.  
  39. Sub Form_Load () 
  40.     ..... do miscellaneous housekeeping and setup routines here ..... 
  41.     Unload Banner                    '  Eliminate user's message  
  42.     Screen.MousePointer = 0   '  set to normal Arrow Pointer  
  43.  End Sub 
  44.   
  45. Using these routines will keep the mouse as an hourglass for most of the 
  46. time required to launch the program.   Use Banner.Label1.Caption to provide
  47. additional status reports to the user for applications which perform 
  48. extensive operations prior to releasing control to the user.  Use 
  49. Banner.Label1.Refresh to get the message out promptly.    
  50.  
  51. An additional method for improving loading speed is to use the MainForm strictly as the 
  52. application's menu.  Only the code for loading other forms should be placed in the 
  53. MainForm.  Using small, single purpose forms will keep overall coding simpler and more 
  54. readable.    
  55.