VERSION 5.00 Begin VB.Form frmAverageScore Caption = "Average Score" ClientHeight = 2556 ClientLeft = 3648 ClientTop = 2736 ClientWidth = 4584 LinkTopic = "Form1" ScaleHeight = 2556 ScaleWidth = 4584 Begin VB.CommandButton cmdAverage Caption = "Average" Height = 372 Left = 3000 TabIndex = 6 Top = 1560 Width = 1452 End Begin VB.CommandButton cmdDone Caption = "Done" Height = 372 Left = 3000 TabIndex = 7 Top = 2040 Width = 1452 End Begin VB.CommandButton cmdEnterScores Caption = "Enter Scores" Height = 372 Left = 3000 TabIndex = 5 Top = 1080 Width = 1452 End Begin VB.Label lblNumberOfScores Height = 252 Left = 240 TabIndex = 1 Top = 1080 Width = 372 End Begin VB.Label lblScoresMessage Height = 252 Left = 840 TabIndex = 2 Top = 1080 Width = 1932 End Begin VB.Label lblHelpMessage Caption = "Select the Enter Scores button to enter test scores. Select the Average button to compute the average of the scores." Height = 612 Left = 240 TabIndex = 0 Top = 120 Width = 3972 End Begin VB.Label lblAverage Height = 252 Left = 1560 TabIndex = 4 Top = 1680 Width = 372 End Begin VB.Label lblAverageMessage Height = 252 Left = 240 TabIndex = 3 Top = 1680 Width = 1092 End End Attribute VB_Name = "frmAverageScore" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' Chapter 6 Average Score ' 3/99 Option Explicit Private intNumberOfScores As Integer, intTotalPoints As Integer Private Sub cmdEnterScores_Click() Const strTitle As String = "Grades" Const strPrompt As String = "Enter a test score (-1 to finish):" Const intSentinel As Integer = -1 'Loop flag Dim intScore As Integer, strTempScore As String lblAverageMessage.Caption = "" 'Clear message lblAverage.Caption = "" 'Clear current average lblNumberOfScores.Caption = "" 'Clear number of scores lblScoresMessage.Caption = "" 'Clear scores message intNumberOfScores = 0 'Initialize global counter intTotalPoints = 0 'Initialize global accumulator strTempScore = InputBox(strPrompt, strTitle) 'Get score 'Determine if Cancel button was selected in input box If strTempScore = "" Then 'Test string returned intScore = intSentinel 'Cancel selected Else intScore = strTempScore 'Score entered End If Do While intScore <> intSentinel intNumberOfScores = intNumberOfScores + 1 'Count score intTotalPoints = intTotalPoints + intScore 'Update total strTempScore = InputBox(strPrompt, strTitle) 'Get score 'Determine if Cancel button was selected in input box If strTempScore = "" Then 'Test string returned intScore = intSentinel 'Cancel selected Else intScore = strTempScore 'Score entered End If Loop lblNumberOfScores.Caption = intNumberOfScores lblScoresMessage.Caption = "scores have been entered" End Sub Private Sub cmdAverage_Click() Dim dblAverage As Double If intNumberOfScores > 0 Then dblAverage = intTotalPoints / intNumberOfScores 'Compute average lblAverageMessage.Caption = "The average is" lblAverage.Caption = dblAverage 'Display average Else lblAverageMessage.Caption = "The average is" lblAverage.Caption = 0 End If End Sub Private Sub cmdDone_Click() Unload Me End Sub