Form Events and Sub Procedures Can Be Exposed

Last reviewed: April 8, 1997
Article ID: Q143311
4.00 WINDOWS kbprg

The information in this article applies to:

  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, version 4.0, for Windows

SUMMARY

Visual Basic 4.0 forms are public. Therefore the form events and sub procedures are prefaced by the private keyword so they are not publicly visible members of the form.

MORE INFORMATION

In Visual Basic 3.0, a form's events and sub procedures are private to the form, and cannot be accessed outside of the form's scope. Because a Visual Basic 4.0 form is public, its events and sub procedures can be exposed by either prefacing it with Public or by removing Private from the event.

Step-by-Step Example

The following example works in Visual Basic 4.0 but not in Visual Basic 3.0. To create the program, do the following:

  1. Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.

  2. In Form1 enter the following code:

       Sub DispMsg ()
           MsgBox "Inside Sub"
       End Sub
    
    

  3. Add a module to the project and in Module1 enter the following code:

       Sub main()
          'some other code stuff could go here
          Call Form1.DispMsg
       End Sub
    
    

  4. Select the Tools, Options menu item and the Project tab. Set Startup Form to Sub Main.

  5. Run this program. The Module1 Main sub procedure calls the DispMsg sub procedure in the form.

NOTE: Invoking an event through code is not good programming practice. However, you can get at routines and form events if needed. Just ensure that they are visible members of the class (the form in this case).


Additional reference words: 4.00 vb4win
KBCategory: kbprg
KBSubcategory: PrgOther PrgCtrls*
Keywords : kbprg PrgCtrls PrgOther kbprg
Version : 4.0
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.