Public Class Form1
    Dim aparitii(25) As Integer
    Dim litera As Integer
    Dim reguli(,) As String = {{"cuvânt ce începe cu aceasta litera"}, {"cuvânt ce conţine aceasta litera (dar nu pe prima poziţie)"}, {"cuvânt ce conţine două apariţii ale literei respective"}}
    Dim regula As Integer
    Dim corecte As Integer = 0
    Dim aparitii3 As Integer
    Dim generari As Integer = 0
    Dim afisare As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Randomize()
        litera = CInt(Int(122 - 96) * Rnd() + 97)
        Label1.Text = Chr(litera)
        aparitii(litera - 97) += 1
        regula = CInt(Int(2)) * Rnd() + 0
        Label3.Text = reguli(regula, 0)
        generari += 1
        Button2.Enabled = False
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If TextBox1.Text = "" Then
            Button2.Enabled = False
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If TextBox1.Text = "" Then
            Button2.Enabled = False
        Else
            Button2.Enabled = True
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        aparitii3 = 0
        If regula = 0 Then
            If TextBox1.Text(0) = Label1.Text(0) Then
                corecte += 1
            End If
        End If
        If regula = 1 Then
            For i = 0 To Len(TextBox1.Text)
                If TextBox1.Text(i) = Label1.Text(0) Then
                    corecte += 1
                    Exit For
                End If
            Next
        End If
        If regula = 2 Then
            For i = 0 To Len(TextBox1.Text)
                If TextBox1.Text(i) = Label1.Text(0) Then
                    aparitii3 += 1
                    If aparitii3 = 2 Then
                        corecte += 1
                        Exit For
                    End If
                End If
            Next
        End If
        Button2.Enabled = False
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        afisare = ""
        For i = 97 To 122
            afisare = afisare & Chr(10 & Chr(13)) & Chr(i) & " -> " & Str(aparitii(i - 97))
        Next
        MsgBox("Numărul total de litere generate: " & Str(generari) & ";" & Chr(10) & Chr(13) & "Numărul de generări pentru fiecare literă: " & afisare & ";" & Chr(10) & Chr(13) & "Numărul de răspunsuri corecte indicate de utilizator: " & Str(corecte) & ";")
    End Sub
End Class
