PROGRAMACIÓ D'APLICACIONS EDUCATIVES AMB VISUAL BASICMÒDUL 5

Fitxer: m5p1.frm

Definició dels objectes. Interfície d'usuari

Recordeu que això no ho podeu editar directament. Per fer-ho incorporeu nous objectes de la paleta en el vostre formulari. I per canviar els valors seleccioneu l'objecte i escolliu la propietat a canviar en la finestra Properties.

VERSION 5.00
Begin VB.Form frmPreguntesRespostes 
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   Caption         =   "Preguntes i respostes"
   ClientHeight    =   2865
   ClientLeft      =   1875
   ClientTop       =   1800
   ClientWidth     =   6015
   BeginProperty Font 
      Name            =   "MS Sans Serif"
      Size            =   8.25
      Charset         =   0
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   ForeColor       =   &H80000008&
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2865
   ScaleWidth      =   6015
   Begin VB.CommandButton cmdNovaPregunta 
      Appearance      =   0  'Flat
      Caption         =   "&Nova Pregunta"
      Height          =   735
      Left            =   1680
      TabIndex        =   3
      Top             =   120
      Width           =   2295
   End
   Begin VB.TextBox txtAvaluacióResposta 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      ForeColor       =   &H00000000&
      Height          =   495
      Left            =   600
      MultiLine       =   -1  'True
      TabIndex        =   2
      Top             =   2280
      Width           =   4815
   End
   Begin VB.TextBox txtResposta 
      Appearance      =   0  'Flat
      Height          =   285
      Left            =   3000
      TabIndex        =   1
      Top             =   1560
      Width           =   2415
   End
   Begin VB.TextBox txtPregunta 
      Appearance      =   0  'Flat
      ForeColor       =   &H000000FF&
      Height          =   285
      Left            =   600
      TabIndex        =   0
      Top             =   1080
      Width           =   4815
   End
   Begin VB.Label lblResposta 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "Escriviu la resposta:"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   600
      TabIndex        =   4
      Top             =   1560
      Width           =   2295
   End
End


Codi del programa. Programació de respostes a events

Attribute VB_Name = "frmPreguntesRespostes"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit

Dim m As Integer
Dim MatriuPreguntes(3, 2) As String

Private Sub cmdNovaPregunta_Click()
    txtAvaluacióResposta.Visible = False
    Randomize
    m = Int(3 * Rnd) + 1

    txtPregunta.Text = MatriuPreguntes(m, 1)
    lblResposta.Visible = True
    txtPregunta.Visible = True
    txtResposta.Visible = True
    txtResposta.SetFocus
    txtResposta.Text = ""
End Sub

Private Sub Form_Load()
    IniciaMatriuPreguntes
    txtPregunta.Visible = False
    lblResposta.Visible = False
    txtResposta.Visible = False
    txtAvaluacióResposta.Visible = False
End Sub

Private Sub IniciaMatriuPreguntes()
    MatriuPreguntes(1, 1) = "Quin és el nom de la ciutat on hi ha una torre inclinada molt famosa?"
    MatriuPreguntes(1, 2) = "Pisa"
    MatriuPreguntes(2, 1) = "Quants dies té un any de traspàs?"
    MatriuPreguntes(2, 2) = "366"
    MatriuPreguntes(3, 1) = "Quin mes es celebra Sant Jordi?"
    MatriuPreguntes(3, 2) = "Abril"
End Sub

Private Sub txtResposta_KeyDown(Keycode As Integer, Shift As Integer)
    If Keycode = 13 Then
        txtAvaluacióResposta.Visible = True
       
        If (MatriuPreguntes(m, 2) = txtResposta.Text) Then
             txtAvaluacióResposta.Text = "Molt bé"
         Else
             txtAvaluacióResposta.Text = "La resposta correcta és: " & MatriuPreguntes(m, 2)
        End If
    End If
End Sub