Saturday, March 19, 2011
Looping Statement repetition.
----- Visual Basic 0.6 ( Looping Repetition )
------- GRADE CALCULATOR CODES.
Dim intCount As Integer, strChecked As String
If chkDone(Index).Value = vbChecked Then
cmdDisplay.Enabled = True
txtScore(Index).Enabled = True
txtScore(Index).SetFocus
Else
txtScore(Index).Text = 0
txtScore(Index).Enabled = False
strChecked = "N"
Do While intCount <= 4 And strChecked = "N"
If chkDone(intCount).Value = vbChecked Then
strChecked = "y"
End If
intCount = intCount + 1
Loop
If strChecked = "n" Then
cmdDisplay.Enabled = False
End If
End If
End Sub
Private Sub cmdClear_Click()
Dim x As Integer
For x = 0 To 4
chkDone(x).Value = False
txtScore(x).Text = ""
Next x
lblGrade.Caption = ""
txtName.SetFocus
End Sub
Private Sub cmdDisplay_Click()
Dim intEarned As Integer, intPossible As Integer
Dim sngRatio As Single, intCount As Integer
For intCount = 0 To 4
If chkDone(intCount).Value = vbChecked Then
intEarned = intEarned + Val(txtScore(intCount).Text)
Select Case intCount
Case 0 To 2
intPossible = intPossible + 10
Case Else
intPossible = intPossible + 50
End Select
End If
Next intCount
sngRatio = intEarned / intPossible
Select Case sngRatio
Case Is >= 0.9
lblGrade.Caption = "A"
Case Is >= 0.8
lblGrade.Caption = "B"
Case Is >= 0.7
lblGrade.Caption = "C"
Case Is >= 0.6
lblGrade.Caption = "D"
Case Else
lblGrade.Caption = "F"
End Select
End Sub
Private Sub cmdExit_Click()
Unload frmGrade
End Sub
Private Sub cmdPrint_Click()
PrintForm
End Sub
Private Sub Form_Load()
frmGrade.Top = (Screen.Height - frmGrade.Height) / 2
frmGrade.Left = (Screen.Width - frmGrade.Width) / 2
End Sub
Private Sub Form_Unload(Cancel As Integer)
Const conBtns As Integer = vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal
Dim intUserResponse As Integer
intUserResponse = MsgBox("Do you want to exit?", conBtns, "Grade Application")
If intUserResponse = vbNo Then 'User does not want to quit the app
Cancel = 1 'prevent form unload.
End If
End Sub
Private Sub txtScore_GotFocus(Index As Integer)
txtScore(Index).SelStart = 0
txtScore(Index).SelLength = Len(txtScore(Index).Text)
End Sub
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment