' Mr. Minich
' Period 1
' Ch4Demo3
' 11/2/2000
' Purpose - to illustrate the use of a control expression that contains a
'           Boolean condition as well as to illustrate the use of a
'           Select Case statement that uses relational operators.

Option Explicit

Private Sub Form_Activate()
    ' determines whether a number inputted by the user is an even or odd number
    
    Dim intUserInput As Integer     ' integer inputted by user
    
    frmMain.AutoRedraw = True       ' so output will show on the form
    
    intUserInput = InputBox("Enter your grade percentage:")
    
    frmMain.Print "The inputted number " & intUserInput;    ' semicolon causes next printed
                                                            '   string of output to continue on
                                                            '   the same line
    
    ' Any even number will return a remainder of 0 when divided by 2 while any odd number
    '   will return a remainder of 1 when divided by 2. The Mod function is very useful
    '   in computer science for determining whether a value is even or odd.
    
    If ((intUserInput Mod 2 = 0) And (intUserInput <> 0)) Then  ' testing for even numbers
        frmMain.Print " is an even number."
    ElseIf (intUserInput Mod 2 = 1) Then                        ' testing for odd numbers
        frmMain.Print " is an odd number."
    Else
        frmMain.Print " is considered to be neither odd nor even."
    End If
    
    frmMain.Print                  ' printing blank line
    
    Select Case intUserInput       ' determining user's grade
    Case 100
        frmMain.Print "Congratulations you earned an A+ !"
    Case Is >= 90
        frmMain.Print "Your grade would be an A."
    Case Is >= 80
        frmMain.Print "Your grade would be a B."
    Case Is >= 70
        frmMain.Print "Your grade would be a C."
    Case Is >= 60
        frmMain.Print "Your grade would be a D."
    Case Is >= 0
        frmMain.Print "Your grade would be an F."
    Case Is < 0
        frmMain.Print "A negative grade percentage was entered."
    Case Else
        frmMain.Print "An illegal exception occurred. See the programmer."
    End Select
    
End Sub

' Notes

' The If/ElseIf statement uses a Boolean condition with the logical And operator checking to
'   make sure that intUserInput is even but not zero. If it is zero then the Else case
'   applies since zero is not considered to be odd or even.

' When a case within a Select Case is a specific value, that value is typed after the keyword
'   Case. However, you must use the keyword Is followed by the necessary relational operator
'   such as >= .

' The Select Case statement's Else case will only apply to situations that were not expected by
'   the programmer.

' The Select Case statement in the program above could be replaced by the following If/Else
'   statement. It is considered to be better style to use a Select Case in this situation
'   because Select Case statements are usually considered to be easier to read when there
'   are 3 or more cases.

'   If (intUserInput = 100) Then
'       frmMain.Print "Congratulations you earned an A+ !"
'   ElseIf (intUserInput >= 90) Then
'       frmMain.Print "Your grade would be a A."
'   ElseIf (intUserInput >= 80) Then
'       frmMain.Print "Your grade would be a B."
'   ElseIf (intUserInput >= 70) Then
'       frmMain.Print "Your grade would be a C."
'   ElseIf (intUserInput >= 60) Then
'       frmMain.Print "Your grade would be a D."
'   ElseIf (intUserInput >= 0) Then
'       frmMain.Print "Your grade would be an F."
'   ElseIf (intUserInput < 0) Then
'       frmMain.Print "A negative grade percentage was entered."
'   Else
'       frmMain.Print "An illegal exception occurred. See the programmer."
'   End If