Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Â
Vb6 ch.6-3 cci
1. VISUAL BASIC 6 â 3 CUBE COMPUTER INSTITUTE (3CCI)
Chapter 6
Multiple Forms
Adding Form to a Project
Steps for adding a form to a project:
1. Select Project Menu from VB6 Menu bar.
2. Choose Add Form.
3. Select Form from the Add Form Dialog Box.
---------------------------------------------------------------------------------------------------------------------------
-----------
The Hide and Show Methods
Display a form with a Show method and conceal a form with the Hide Method.
Show Method
General form - FormName.Show [Style]
The optional style determines whether the form will display modeless or modal.
The values for Style can be 0-modeless and 1-modal, default is 0. You can also use VB
intrinsic constants; vbModal and vbModeless.
When the form is displayed as modal, the user must respond to the form in some way.
No other code can execute until the modal form has been responded to and hidden or
unloaded.
If the form is displayed as modeless, the user may switch to another form.
Examples frmMain.Show 1
frmMain.Show vbModal
frmMain.Show vbModeless
frmMain.Show
Hide Method
General Form â FormName.Hide
Hide method is used to remove a form from the screen.
Example â frmMain.Hide
---------------------------------------------------------------------------------------------------------------------------
Form_Load and Form_Activate
The first time a form is displayed in a project, VB generates two eventsâa Form_Load and
Form_Activate.
The Form_Load event calls the form module into memory.
1
2. VISUAL BASIC 6 â 3 CUBE COMPUTER INSTITUTE (3CCI)
The Form_Activate event occurs after the Form_Load event, just as control is passed to the
Form. Each time the form is shown the Form_Activate event occurs and not the Form_Load
event.
---------------------------------------------------------------------------------------------------------------------------
Me Keyword
The current form can be referred by using the special Keyword Me.
Me acts like a variable and refers to the current active form.
Use Me in place of Form name when coding form statements and methods.
Example: Unload Me
Me.Hide
---------------------------------------------------------------------------------------------------------------------------
Load and Unload Statements
Load â When you show a form, the Load is done automatically.
The only time you will code a Load statement is when you want to load a form but not
display.
General Form â Load FormName
Example: Load frmLogIn
Unload âTo remove a form from the screen, hide it unload it.
Hiding a form removes it from the screen, but the form still remains in the memory.
If you do not need the form for further execution, the best way is to unload the form.
General form â Unload FormName
Example: Unload frmLogin
---------------------------------------------------------------------------------------------------------------------------
Example of SHOW/ HIDE and LOAD /UNLOAD
Standard Code Module
A Standard Code Module is a basic procedure with the extension .bas which is added to the
project.
Standard code module does not contain Form Window. It only contain a Code window. A
standard code module has general declaration section and procedure just like form module.
2
3. VISUAL BASIC 6 â 3 CUBE COMPUTER INSTITUTE (3CCI)
They can contain global (available to the whole application) or module-level declarations of
variables, constants, types, external procedures, and global procedures.
Standard Code Module is visible to all procedures in the module but not to procedure in
the form module.
Adding a Standard Code Module to Project
Steps for adding a Standard Code Module to a project:
1. Select Project Menu from VB6 Menu bar.
2. Choose Add Module.
3. Select Module from the Add Module Dialog Box.
---------------------------------------------------------------------------------------------------------------------------
Global/ Public Variables
If you want variables and constants to be accessible to more than one form in the project, they
must be global variables. To declare global variables, use the Public statement in place of the
Dim statement.
General form â Public Identifier [As Datatype]
Public Const Identifier [As Datatype] = Value
A public variable or constant has a prefix of g.
Static Variables
Static variables retain their value for the life of the project, rather than being initialized for each
call to a procedure. If you need to retain the value in a variable for multiple calls to a procedure,
such as a running total, declare it as Static.
General form â Static Identifier [As DataType]
Static statements can appear only in procedures; Static statements never appear in the General
Declarations section of a module. Static variables do not require a scope prefix, since all static
variables are local.
---------------------------------------------------------------------------------------------------------------------------
Setting the Startup Form
By default, the first form in your application is designated as the startup form. When your
application starts running, this form is displayed.
If you want a different form to display when your application starts, you must change the
startup form.
To change the startup form
1. From the Project menu, choose Project Properties.
2. Choose the General tab.
3. In the Startup Object list box, select the form you want as the new startup form.
4. Choose OK.
---------------------------------------------------------------------------------------------------------------------------
3
4. VISUAL BASIC 6 â 3 CUBE COMPUTER INSTITUTE (3CCI)
Starting Without a Startup Form : SUB MAIN()
Sometimes you might want your application to start without any form initially loaded.
For example, you might want to execute code that loads a data file and then displays one of
several different forms depending on what is in the data file.
You can do this by creating a Sub procedure called Main in a standard module, as in the
following example:
Sub Main()
frmSplash.Show vbModeless
Load frmMain
End Sub
This procedure must be a Sub procedure, and it cannot be in a form module.
To set the Sub Main procedure as the startup object, from the Project menu, choose Project
Properties, select the General tab, and select Sub Main from the Startup Object box.
---------------------------------------------------------------------------------------------------------------------------
Displaying a Splash Screen on Startup
If you need to execute a lengthy procedure on startup, such as loading a large amount of data
from a database or loading several large bitmaps, you might want to display a splash screen on
startup.
A splash screen is a form, usually displaying information such as the name of the application,
copyright information, and a simple bitmap. The screen that is displayed when you start Visual
Basic is a splash screen.
To display a splash screen, use a Sub Main procedure as your startup object and use the Show
method to display the form:
Private Sub Main()
' Show the splash screen.
frmSplash.Show
' Add your startup procedures here.
âŠ
' Show the main form and unload the splash screen.
frmMain.Show
Unload frmSplash
End Sub
The splash screen occupies the user's attention while your startup routines are executing, giving
the illusion that the application is loading faster. When the startup routines are completed, you
can load your first form and unload the splash screen.
Adding a Splash Screen to Project
Steps for Adding a Splash Screen to Project:
1. Select Project Menu from VB6 Menu bar.
2. Choose Add Form.
3. Select Splash Screen from the Add Form Dialog Box.
4
5. VISUAL BASIC 6 â 3 CUBE COMPUTER INSTITUTE (3CCI)
---------------------------------------------------------------------------------------------------------------------------
Displaying a About Box
Adding an About Box to Project
Steps for Adding a About Box to Project:
1. Select Project Menu from VB6 Menu bar.
2. Choose Add Form.
3. Select About Box from the Add Form Dialog Box.
About Box contains the Application Title, Version, and App Description placeholders with
information specific to your application.
5