Comunidad Gambas-es
Countries and Nationalities - Versión para impresión

+- Comunidad Gambas-es (https://gambas-es.org)
+-- Foro: Gambas (https://gambas-es.org/forum-3.html)
+--- Foro: General (https://gambas-es.org/forum-4.html)
+--- Tema: Countries and Nationalities (/thread-1529.html)



Countries and Nationalities - Shell - 25-10-2023

Buenas!

Uno de los ejercicios del curso de Inglés es conocer los países y las nacionalidades.
Lógicamente hay muchas.

Aunque hay muchas utilidades online para estas cosas, con Gambas hago algo parecido
con el fin de hacer test. Rolleyes

En principio el formulario es muy simple.
Puede preguntar la nacionalidad y se debe responder el país o al revés.

[Imagen: l3IGgg5.png]


Lo más gracioso es averiguar una estructura de datos, intercambiar la pregunta, tanto si es para país como para nacionalidad.

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

Que despiste, subo el código. Que es muy sencillo.

Saludos