Rabu, 25 Desember 2013

“Mathematic Test” dengan Visual Basic.NET 2010

Mathematic Test VB.NET

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

Public Class Form1
    Dim Coice As String
    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        End
    End Sub

    Private Sub cmdAddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddition.Click
        BeginTest()
        lblDisplaySubject.Text = "+"
        DisplayRandom()
        Coice = "Addition"
    End Sub

    Private Sub cmdMultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMultiplication.Click
        BeginTest()
        lblDisplaySubject.Text = "X"
        DisplayRandom()
        Coice = "Multiplication"
    End Sub

    Private Sub BeginTest()
        frmMenu.Visible = False
        frmTest.Visible = True
        txtUserInput.Enabled = True
        cmdNext.Enabled = True
        txtUserInput.Focus()
    End Sub

    Private Sub DisplayRandom()
        lblDisplayNo1.Text = Int(Rnd() * 9) + 1
        lblDisplayNo2.Text = Int(Rnd() * 9) + 1
    End Sub

    Private Sub cmdMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMain.Click
        frmTest.Visible = False
        frmMenu.Visible = True
        txtUserInput.Text = ""
        lblInfo.Text = ""
        lblPoint.Text = 0
        lblRemain.Text = 1000
        lblWrong.Text = 0
    End Sub

    Private Sub cmdExitTes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExitTes.Click
        End
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Randomize()
        cmdExit.Focus()
        DisplayRandom()
    End Sub

    Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
        txtUserInput.Text = ""
        txtUserInput.Focus()
        lblInfo.Text = ""
        DisplayRandom()
    End Sub

    Private Sub txtUserInput_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUserInput.KeyPress
        Dim Result, Point, WrongUI, Remain As Integer

        Select Case Coice
            Case "Addition"
                Result = Val(lblDisplayNo1.Text) + Val(lblDisplayNo2.Text)
            Case "Multiplication"
                Result = Val(lblDisplayNo1.Text) * Val(lblDisplayNo2.Text)
        End Select

        If Not (e.KeyChar >= ChrW(Keys.D0) And e.KeyChar <= ChrW(Keys.D9) Or e.KeyChar = ChrW(Keys.Back) Or e.KeyChar = ChrW(Keys.Return)) Then
            e.KeyChar = ChrW(0)
        ElseIf e.KeyChar = ChrW(Keys.Return) Then
            If Val(txtUserInput.Text) = Result Then
                Point = 0
                Point = lblPoint.Text
                lblPoint.Text = Point + 100

                Remain = 1000
                Remain = lblRemain.Text
                lblRemain.Text = Remain - 100

                lblInfo.Text = "Correct" + vbCrLf + "You got 100 point"
                cmdNext.Focus()
            Else
                WrongUI = 0
                WrongUI = lblWrong.Text
                lblWrong.Text = WrongUI + 1

                lblInfo.Text = "Wrong!" + vbCrLf + "the correct answer is " + vbCrLf + Str(Result)
                cmdNext.Focus()
            End If

            If lblRemain.Text = 0 Then
                MsgBox("Congratulation you have finish the test", vbOKOnly + vbInformation, "Winner")
                txtUserInput.Enabled = False
                cmdNext.Enabled = False
                cmdMain.Focus()
            End If

            If lblWrong.Text >= 10 Then
                MsgBox("You have to study more!!!", vbOKOnly + vbInformation, "Loser")
                txtUserInput.Enabled = False
                cmdNext.Enabled = False
                cmdMain.Focus()
            End If

        End If
    End Sub
End Class

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda