Chapter 6 Programs

'Project Show Splash 1
'Programmer: Max Jerrell
'Date: Oct 2001
'Purpose: To show how a splash screen is loaded and
' unloaded
Option Explicit
Private Sub cmdShowSplash_Click()
frmSplash.Show ‘this loads the splash screen
End Sub
The splash screen code is below
'===>This is the splash screen code
Option Explicit
Private Sub Form_KeyPress(KeyAscii As Integer)
'===> This allows a keystroke to unload the splash form
Unload Me
End Sub
Private Sub Form_Load()
lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision
lblProductName.Caption = App.Title
End Sub
Private Sub Frame1_Click()
'===> A mouse click anywhere on the screen unloads the form
Unload Me
End Sub
This program demonstrates the use of multiple forms and global variables
The basic module
'===>This is the main basic module that controls
'===>initial program flow and sets global variables
Option Explicit
'===>Define Global variables
'===>They must be defined as Public to be global.
Public gstrGlobalMessage As String
Public gstrGlobalTitle As String
Public Sub Main()
'===>This sub is executed when the programs starts
'===>executing. It controls the initial program flow.
'===>You can also initialize global variables here
gstrGlobalTitle = "This is the title"
frmSplash.Show 'Show the splash screen
End Sub
The code for frmMain
'Project Global Variables
'Programmer: Max Jerrell
'Date: Oct 2001
'Purpose: This is the main or controlling form.
' This is the form that calls frmSecond and
' this is the form that frmSecond returns to.
' A value is given to the global variable
' through an InputBox().
'===>This is the code for frmMain
Option Explicit
Private Sub cmdExit_Click()
'===>Terminates the program
End
End Sub
Private Sub cmdGetInput_Click()
'===>put information from input box into global string variable
gstrGlobalMessage = InputBox("Enter the global information", "Input Request")
End Sub
Private Sub cmdShowSecondform_Click()
'===> displays the second form
frmSecond.Show
End Sub
Private Sub Form_Load()
'===>This is executed when the form is loaded
lblTitle = gstrGlobalTitle
lblTitle.ForeColor = vbYellow
End Sub
The code for frmSecond
'===>This is the code for the second form
'
Private Sub cmdReturn_Click()
'===>This sub erases the caption, hides frmSecond, and
'===>returns to frmMain
lblOutput.Caption = ""
Me.Hide 'hide this form
frmMain.Show 'show main form
End Sub
Private Sub cmdShowGlobal_Click()
'===>Display the global information
'===>Note that gstrGlobalMessage is not defined in
'===>this form. It has been defined in the
'===>basic module
lblOutput.Caption = gstrGlobalMessage
End Sub
Private Sub Form_Load()
'===>Display the global title
lblTitle.Caption = gstrGlobalTitle
lblTitle.ForeColor = vbBlue
End Sub
The code for the splash screen
'===>Splash Form Code
Option Explicit
Private Sub Form_KeyPress(KeyAscii As Integer)
'===>Any key pressed will unload the form
Unload Me 'unload splash screen
frmMain.Show 'show frmMain
End Sub
Private Sub Form_Load()
lblVersion.Caption = "Version " & App.Major _
& "." & App.Minor & "." & App.Revision
lblProductName.Caption = App.Title
End Sub
Private Sub Frame1_Click()
'===>Click anyplace on the window to unload the form
Unload Me 'Unload splash screen
frmMain.Show 'show frmMain
End Sub
Project Multple Forms I
'Project Name: Multiple Forms I
'Programmer: Max Jerrell
'Date: March, 2000
'Description: Shows how to use multiple forms, global variables
' Splash screens, load form, show, hide,
' about screens
'===>This is the standard code modlue
Option Explicit
' === Define global variables
Sub Main()
frmSplash.Show vbModal '=== Display the splash screen
Load frmDoIt '=== Load main form
End Sub
'Project Name: Multiple Forms I
'Programmer: Max Jerrell
'Date: March, 2000
'Description: Shows how to use multiple forms, global variables
' Splash screens, load form, show, hide,
' about screens
Option Explicit
Private Sub cmdDoIt_Click()
' === Declare local variables
Dim strInput As String
Dim dblX As Double
Dim dblSum As Double
Dim dblMean As Double
Dim dblStandardDeviation As Double
Dim intNumberOfObservations As Integer
'===== Input data
Do
' === Get input
strInput = InputBox("Enter Data == Type END to quit")
If Not IsNumeric(strInput) Then 'Stop if input is not numeric
Exit Do
End If
dblX = Val(strInput)
dblSum = dblSum + dblX ' === add to total
intNumberOfObservations = intNumberOfObservations + 1
Loop
' === compute mean
dblMean = dblSum / intNumberOfObservations
'==== put output in form frmSummary
frmSummary.lblSummary.Caption = "Mean = " & dblMean & vbCrLf _
& "Number of observations = " _
& intNumberOfObservations
End Sub
Private Sub cmdExit_Click()
'==== Exits the program
End
End Sub
Private Sub mnuAbout_Click()
Me.Hide
frmAbout.Show vbModal
End Sub
Private Sub mnuExit_Click()
'=== Exits the program
End
End Sub
Private Sub mnuSummary_Click()
'=== Call the Summary form
Me.Hide
frmSummary.Show vbModal
End Sub
'===>This is the code for frmSummary
Option Explicit
Private Sub cmdClose_Click()
Me.Hide
frmDoIt.Show
End Sub
'===>The code for frmSplash
Option Explicit
Private Sub cmdClose_Click()
Unload Me
frmDoIt.Show vbModal
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Unload Me
End Sub
'Private Sub Form_Load()
' lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision
' lblProductName.Caption = App.Title
'End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
The code for frmAbout is to lengthy to show.
'===>Project Multiple Forms Example
'Programmer Max Jerrell
'Date Oct 2001
'This is the main module. It loads the splash screen
'and provides global variables to communicate between
'forms
Option Explicit
' === Define global variables
Public gdblMean As Double
Public gintNumberOfObservations As Integer
Sub Main()
frmSplash.Show vbModal '=== Display the splash screen
Load frmDoIt '=== Load main form
End Sub
'Project Name: Multiple Forms Example
'Programmer: Max Jerrell
'Date: March, 2000
'Description: Shows how to use multiple forms, global variables
' Splash screens, load form, show, hide,
' about screens
Option Explicit
Private Sub cmdDoIt_Click()
' === Declare local variables
Dim strInput As String
Dim dblX As Double
Dim dblSum As Double
Dim dblMean As Double
Dim dblStandardDeviation As Double
Dim intNumberOfObservations As Integer
'===== Input data
Do
' === Get input
strInput = InputBox("Enter Data == Type END to quit")
If Not IsNumeric(strInput) Then 'Stop if input is not numeric
Exit Do
End If
dblX = Val(strInput)
dblSum = dblSum + dblX ' === add to total
intNumberOfObservations = intNumberOfObservations + 1
Loop
' === compute mean
dblMean = dblSum / intNumberOfObservations
'==== set global variables
gdblMean = dblMean
gintNumberOfObservations = intNumberOfObservations
End Sub
Private Sub cmdExit_Click()
'==== Exits the program
End
End Sub
Private Sub mnuAbout_Click()
Me.Hide
frmAbout.Show vbModal
End Sub
Private Sub mnuExit_Click()
'=== Exits the program
End
End Sub
Private Sub mnuNextForm_Click()
End Sub
Private Sub mnuSummary_Click()
'=== Call the Summary form
Me.Hide
frmSummary.Show vbModal
End Sub
'===>The code for frmSummary
Option Explicit
Private Sub cmdClose_Click()
Me.Hide
frmDoIt.Show
End Sub
Private Sub cmdMean_Click()
'=== Display Mean
lblMean.Caption = "Mean = " & gdblMean
End Sub
Private Sub cmdStanDev_Click()
'=== Computes standard deviation
lblStanDev.Caption = "Available in professional version only"
End Sub
Private Sub Form_Load()
End Sub
‘=The code for frmSplash
Option Explicit
Private Sub cmdClose_Click()
Unload Me
frmDoIt.Show vbModal
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Unload Me
frmDoIt.Show vbModal
End Sub
'Private Sub Form_Load()
' lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision
' lblProductName.Caption = App.Title
'End Sub
Private Sub Frame1_Click()
Unload Me
frmDoIt.Show vbModal
End Sub