Mark sheet Program
Code
Option Explicit
Dim marks As String
Dim Perc As Double
Private Sub Command1_Click()
'Comments
'DATA VALIDATION IS VERY IMPORTANT FOR YOUR PROGRAM"
'IF YOU HAVE EMPTY TEXT BOXES AND WANTS TO CALCULATE
'GRADE AND PERCENTAGE THEN PROGRAM INFORM THAT MISTAKE
'SIMILARLY IF YOU ENTER MARKS GREATER THAN 100 IN EACH
'SUBJECT THEN PROGRAM INFORM YOU
' IMPORTANT NOTE: THIS VALIDATION CAN BE MADE BY TWO METHODS
'BY USING OR OPERATORS.
'BY USING IF THEN CONDITIONAL STATEMENT
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then
MsgBox "Marks must be Enter"
Exit Sub
End If
If Text1.Text > 100 Then
MsgBox "Please Enter Correct Marks"
Text1.Text = ""
Text1.SetFocus
End If
If Text2.Text > 100 Then
MsgBox "Please Enter Correct Marks"
Text2.Text = ""
Text2.SetFocus
End If
If Text3.Text > 100 Then
MsgBox "Please Enter Correct Marks"
Text3.Text = ""
Text3.SetFocus
End If
If Text4.Text > 100 Then
MsgBox "Please Enter Correct Marks"
Text4.Text = ""
Text4.SetFocus
End If
If IsNumeric(Text1.Text) = False Or IsNumeric(Text2.Text) = False Or IsNumeric(Text3.Text) = False
Or IsNumeric(Text4.Text) = False Then
MsgBox "Please Enter Numric Value"
Exit Sub
End If
marks = Val(Text1) + Val(Text2) + Val(Text3) + Val(Text4)
Perc = marks * 100 / 400
Select Case marks
Case Is >= 320
MsgBox "You have got A+ Grade"
MsgBox Perc
Case 280 To 319
MsgBox "You have got A Grade"
MsgBox Perc
Case 240 To 279
MsgBox "You have got B Grade"
MsgBox Perc
Case 200 To 239
MsgBox "You have got C Grade"
MsgBox Perc
Case 180 To 199
MsgBox "You have got D Grade"
MsgBox Perc
Case Is < 199
MsgBox "Sorry My Dear Please Try Next Year "
MsgBox "No Percentage"
End Select
End Sub
Private Sub Command3_Click()
marks = Val(Text1) + Val(Text2) + Val(Text3) + Val(Text4)
Perc = marks * 100 / 400
If marks >= 320 Then
MsgBox "You have got A+ Grade"
MsgBox Perc
ElseIf marks >= 280 And marks < 320 Then ' Check by using OR Operators
MsgBox "You have got A Grade"
MsgBox Perc
ElseIf marks >= 240 And marks < 279 Then
MsgBox "You have got B Grade"
MsgBox Perc
ElseIf marks >= 200 And marks < 239 Then
MsgBox "You have got C Grade"
ElseIf marks >= 180 And marks < 199 Then
MsgBox "You have got D Grade"
MsgBox Perc
Else
MsgBox "Sorry My Dear Please Try Next Year "
MsgBox "No Percentage"
End If
End Sub