Public Class Form1
    Dim scor1 As Integer
    Dim scor2 As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        KeyPreview = True
        Button1.Enabled = False
        Button2.Enabled = False
        TextBox1.Enabled = True
        Label5.Hide()
        Randomize()
        Label1.Text = Str(CInt(Int(100) * Rnd()))
        Label3.Text = Str(CInt(Int(100) * Rnd()))
        If CInt(Int(1) * Rnd()) = 0 Then
            Label2.Text = "+"
        Else
            Label2.Text = "-"
        End If

    End Sub
    Private Sub textbox1_GotFocus(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.GotFocus
        TextBox1.SelectionStart = 0
        TextBox1.SelectionLength = Len(TextBox1.Text)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not IsNumeric(TextBox1.Text) Then
            MsgBox("Introduceti un numar!")
            TextBox1.Focus()
        Else
            Button2.Enabled = True
            If (Label2.Text = "+") Then
                If (CInt(TextBox1.Text) = CInt(Label1.Text) + CInt(Label3.Text)) Then
                    scor1 += 1
                    scor2 += 1
                    Label5.Text = "Raspuns corect!"
                    Label5.Show()
                    TextBox1.Enabled = False
                Else
                    scor2 += 1
                    Label5.Text = "Raspuns gresit!"
                    Label5.Show()
                    TextBox1.Enabled = False
                End If
            End If
            If (Label2.Text = "-") Then
                If (CInt(TextBox1.Text) = CInt(Label1.Text) - CInt(Label3.Text)) Then
                    scor1 += 1
                    scor2 += 1
                    Label5.Text = "Raspuns corect!"
                    Label5.Show()
                    TextBox1.Enabled = False
                    Button2.Enabled = true
                Else
                    scor2 += 1
                    Label5.Text = "Raspuns gresit!"
                    Label5.Show()
                    TextBox1.Enabled = False
                End If
            End If
            Button1.Enabled = False
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Enabled = True
        Label5.Hide()
        Randomize()
        Label1.Text = Str(CInt(Int(100) * Rnd()))
        Label3.Text = Str(CInt(Int(100) * Rnd()))
        If CInt(Int(1) * Rnd()) = 0 Then
            Label2.Text = "+"
        Else
            Label2.Text = "-"
        End If
        TextBox1.Focus()
        TextBox1.Text = ""
        Button1.Enabled = False
        Button2.Enabled = False
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If scor2 <> 0 Then
            MsgBox("Ati raspuns la " & Str(scor2) & " intrebari si ati obtinut un scor de " & String.Format("{0:F}", (scor1 / scor2) * 100) & "%")
            Me.Close()
        Else
            MsgBox("Nu ati raspuns la nicio intrebare!")
            Me.Close()
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Button1.Enabled = True
    End Sub

    Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Return Then
            Button1.PerformClick()
        End If
    End Sub

End Class
