INFO: Form Events and Sub Procedures Can Be Exposed
ID: Q143311
|
The information in this article applies to:
-
Microsoft Visual Basic for Windows Learning, Professional, and Enterprise Editions, versions 5.0, 6.0
-
Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, version 4.0, for Windows
SUMMARY
Starting with 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 were private to the
form, and could not be accessed outside of the form's scope. Because a form
is public in Visual Basic 4.0 and higher, 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 and higher but not in
Visual Basic 3.0. To create the program, do the following:
- 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.
- In Form1 enter the following code:
Sub DispMsg ()
MsgBox "Inside Sub"
End Sub
- 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
- For VB4, select the Tools, Options menu item and the Project tab. Set
Startup Form to Sub Main.
- For VB5/6: Select the Project, Properties menu item and the General tab.
Set the Startup Object to Sub Main.
- 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 query words:
kbVBp400 kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport KbVBA kbControl
Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbinfo
|