“Mathematic Test” dengan Visual Basic 6.0
Mohon maaf karena terlalu banyak setingan properties yang saya gunakan jadi saya tidak dapat menyertainya di post ini. Namun berikut event program aplikasi ini: (namun apabila teman-teman ingin mencoba sendiri, saya lampirkan program lengkapnya di sini) Trims
Dim Coice As String
Private Sub cmdExitTes_Click()
End
End Sub
Private Sub cmdNext_Click()
txtUserInput.Text = ""
txtUserInput.SetFocus
lblInfo.Caption = ""
DisplayRandom
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdAddition_Click()
BeginTest
lblDisplaySubject.Caption = "+"
DisplayRandom
Coice = "Addition"
End Sub
Private Sub cmdMultiplication_Click()
BeginTest
lblDisplaySubject.Caption = "X"
DisplayRandom
Coice = "Multiplication"
End Sub
Private Sub cmdMain_Click()
frmTest.Visible = False
frmMenu.Visible = True
txtUserInput.Text = ""
lblInfo.Caption = ""
lblPoint.Caption = 0
lblWrong.Caption = 0
lblRemain.Caption = 1000
End Sub
Private Sub Form_Load()
Randomize
DisplayRandom
End Sub
Private Sub txtUserInput_KeyPress(KeyAscii As Integer)
Dim Result, Point, WrongUI, Remain As Integer
Select Case Coice
Case "Addition"
Result = Val(lblDisplayNo1.Caption) + Val(lblDisplayNo2.Caption)
Case "Multiplication"
Result = Val(lblDisplayNo1.Caption) * Val(lblDisplayNo2.Caption)
End Select
If Not (KeyAscii >= vbKey0 And KeyAscii <= vbKey9 Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
KeyAscii = 0
ElseIf KeyAscii = vbKeyReturn Then
If txtUserInput.Text = Result Then
Point = 0
Point = lblPoint.Caption
lblPoint.Caption = Point + 100
Remain = 1000
Remain = lblRemain.Caption
lblRemain.Caption = Remain - 100
lblInfo.Caption = "Correct" + vbCrLf + "You got 100 point"
cmdNext.SetFocus
Else
WrongUI = 0
WrongUI = lblWrong.Caption
lblWrong.Caption = WrongUI + 1
lblInfo.Caption = "Wrong!" + vbCrLf + "the correct answer is " + vbCrLf + Str(Result)
cmdNext.SetFocus
End If
If lblRemain.Caption = 0 Then
MsgBox "Congratulation you have finish the test", vbOKOnly + vbInformation, "Winner"
txtUserInput.Enabled = False
cmdNext.Enabled = False
cmdMain.SetFocus
End If
If lblWrong.Caption >= 10 Then
MsgBox "You have to study more!!!", vbOKOnly + vbInformation, "Loser"
txtUserInput.Enabled = False
cmdNext.Enabled = False
cmdMain.SetFocus
End If
End If
End Sub
Private Sub DisplayRandom()
lblDisplayNo1.Caption = Int(Rnd * 9) + 1
lblDisplayNo2.Caption = Int(Rnd * 9) + 1
End Sub
Private Sub BeginTest()
frmMenu.Visible = False
frmTest.Visible = True
txtUserInput.Enabled = True
cmdNext.Enabled = True
txtUserInput.SetFocus
End Sub
Label: VB6
0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda