' Ch. 8 Demo Program #2
' Mr. Minich
' This program illustrates the user of user-defined types and an array
' of a user-defined type.
Option Explicit
Private Type Student ' a user-defined type definition
strLastName As String
strFirstName As String
sngPercent As Single
strLetterGrade As String
End Type
Dim mudtRoster(0 To 4) As Student ' students in class
Private Sub cmdEnter_Click()
Static J As Integer ' control variable
mudtRoster(J).strFirstName = txtFirstName
mudtRoster(J).strLastName = txtLastName
mudtRoster(J).sngPercent = Val(txtPercent)
Select Case mudtRoster(J).sngPercent
Case Is >= 90
mudtRoster(J).strLetterGrade = "A"
Case Is >= 80
mudtRoster(J).strLetterGrade = "B"
Case Else
mudtRoster(J).strLetterGrade = "C"
End Select
J = J + 1
txtFirstName = "" ' clearing the text boxes
txtLastName = ""
txtPercent = ""
If J = 5 Then
MsgBox "Thanks for entering the info!"
cmdEnter.Enabled = False
End If
End Sub
Private Sub cmdGrades_Click()
Dim J As Integer 'loop variable
For J = 1 To 5
MsgBox "Student 1 earned a " & mudtRoster(J - 1).strLetterGrade
Next J
End Sub