📄 avgsent.frm
字号:
VERSION 5.00
Begin VB.Form frmAverage
Caption = "Fig. 4.12: Class Average Program"
ClientHeight = 1890
ClientLeft = 2895
ClientTop = 2535
ClientWidth = 4380
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 1890
ScaleWidth = 4380
Begin VB.CommandButton cmdExit
BackColor = &H80000005&
Caption = "Exit"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 2640
TabIndex = 2
Top = 960
Width = 1455
End
Begin VB.CommandButton cmdEnterData
BackColor = &H80000005&
Caption = "Enter Grades"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 120
TabIndex = 0
Top = 945
Width = 1935
End
Begin VB.Label lblAverage
Caption = "Press Enter Grades to Start."
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 120
TabIndex = 1
Top = 240
Width = 3975
End
End
Attribute VB_Name = "frmAverage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 4.12
' Class average program with
' sentinel-controlled repetition
Option Explicit ' General declaration
Private Sub cmdEnterData_Click()
Dim total As Integer ' Sum of all grades input
Dim counter As Integer ' Number of grades input
Dim grade As Integer ' Current grade
Dim average As Single ' Floating-point average
Dim message As String ' Text displayed in Label
' Initialization phase
total = 0
counter = 0
' Processing phase
grade = InputBox("Enter grade: -1 to end", "VBHTP")
' Loop until grade has a -1 value
Do Until grade = -1
total = total + grade ' Add grade to total
counter = counter + 1 ' Increment counter
' Input the next grade. When -1 is assigned,
' the loop continuation condition becomes True
grade = InputBox("Enter grade: -1 to end", "VBHTP")
Loop
' Termination phase
If counter <> 0 Then ' Prevent division by zero
average = total / counter ' Floating-point division
message = "Class average is "
' Format average and concatenate to message
message = message & Format$(average, "Fixed")
lblAverage.Caption = message
Else ' counter is 0
lblAverage.Caption = "No grades were entered."
End If
End Sub
Private Sub cmdExit_Click()
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -