Código:
' Gambas class file
Private countriesYnationalities As New String[][]
Private answer As String
Private formtitle As String = "Countries and Nacionalities"
Private index As Integer
Public Sub Form_Open()
Me.Title = formtitle
Randomize
countriesYnationalities.Add(["Spain", "Spanish"])
countriesYnationalities.Add(["England", "English"])
countriesYnationalities.Add(["Irland", "Irish"])
countriesYnationalities.Add(["Poland", "Polish"])
countriesYnationalities.Add(["Scotland", "Scottish"])
countriesYnationalities.Add(["Turkey", "Turkish"])
countriesYnationalities.Add(["Germany", "German"])
countriesYnationalities.Add(["Mexico", "Mexican"])
countriesYnationalities.Add(["the United States", "American"])
countriesYnationalities.Add(["Italy", "Italian"])
countriesYnationalities.Add(["Argentina", "Argentinian"])
countriesYnationalities.Add(["Brazil", "Brazilian"])
countriesYnationalities.Add(["Egypt", "Egyptian"])
countriesYnationalities.Add(["Hungary", "Hungarian"])
countriesYnationalities.Add(["Russia", "Russian"])
countriesYnationalities.Add(["China", "Chinese"])
countriesYnationalities.Add(["Japan", "Japanese"])
countriesYnationalities.Add(["the Czech Republic", "Czech"])
countriesYnationalities.Add(["France", "French"])
countriesYnationalities.Add(["Switzerland", "Swiss"])
countriesYnationalities.Add(["Chile", "Chilean"])
countriesYnationalities.Add(["Peru", "Peruvian"])
countriesYnationalities.Add(["Colombia", "Colombian"])
countriesYnationalities.Add(["Morocco", "Moroccan"])
countriesYnationalities.Add(["Ecuador", "Ecuadorian"])
'Reference to country and answer nacinonality
'Print countriesYnationalities[Rand(0, countriesYnationalities.max)][0]
'Reference to nacionality and answer country
'Print countriesYnationalities[Rand(0, countriesYnationalities.max)][1]
btnQuestion.SetFocus()
End
Public Sub btnQuestion_Click()
Dim questionnumber As Integer
Dim answernumber As Integer
index = Rand(0, countriesYnationalities.max)
questionnumber = Rand(1)
answernumber = IIf(questionnumber = 0, 1, 0)
Label1.Text = countriesYnationalities[index][questionnumber]
answer = countriesYnationalities[index][answernumber]
End
Public Sub TextBox1_KeyPress()
Dim useranswer As String
If Key.Code = Key.Enter Or Key.Code = Key.Return Then
If TextBox1.Text = answer Then
'Remove the index for not repeat the same question
countriesYnationalities.Remove(index)
useranswer = "Correct!"
Else
useranswer = "Incorrect"
Endif
Me.Caption = formtitle & " : " & useranswer
Endif
End