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

Fitxer: m5p2.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 b"
   ClientHeight    =   3945
   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     =   3945
   ScaleWidth      =   6015
   Begin VB.TextBox txtNúmRegistres 
      Appearance      =   0  'Flat
      Height          =   375
      Left            =   1680
      TabIndex        =   8
      Top             =   360
      Width           =   855
   End
   Begin VB.CommandButton cmdAfegir 
      Appearance      =   0  'Flat
      Caption         =   "Afegir una nova pregunta al fitxer de dades"
      Height          =   495
      Left            =   1680
      TabIndex        =   6
      Top             =   3000
      Width           =   3855
   End
   Begin VB.CommandButton cmdAcabar 
      Appearance      =   0  'Flat
      Caption         =   "Acabar"
      Height          =   495
      Left            =   600
      TabIndex        =   5
      Top             =   3000
      Width           =   855
   End
   Begin VB.CommandButton cmdPreguntar 
      Appearance      =   0  'Flat
      Caption         =   "&Realitzar una pregunta"
      Height          =   735
      Left            =   3120
      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 lblNumRegistres 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "Número de registre:"
      ForeColor       =   &H80000008&
      Height          =   495
      Left            =   600
      TabIndex        =   7
      Top             =   240
      Width           =   975
   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 Fitxer As String
Dim Preg As Preguntes, Pregaux As Preguntes
Dim NúmRegs As Integer

Private Sub cmdAcabar_Click()
    Close #1
    End
End Sub

Private Sub cmdAfegir_Click()
    Dim Títol As String, Missatge As String

    Títol = "Introducció de la pregunta a afegir"
    Missatge = "Escriviu la pregunta que voleu incorporar: "
    Pregaux.Pregunta = InputBox(Missatge, Títol)
    Títol = "Introducció de la resposta"
    Missatge = "Escriviu la resposta a la pregunta anterior: "
    Pregaux.Resposta = InputBox(Missatge, Títol)
    If Pregaux.Pregunta <> "" Or Pregaux.Resposta <> "" Then
        NúmRegs = NúmRegs + 1
        Put #1, NúmRegs, Pregaux
        txtNúmRegistres = Str(NúmRegs)
    End If
End Sub

Private Sub cmdPreguntar_Click()
    If NúmRegs > 0 Then
        txtAvaluacióResposta.Visible = False
        Randomize
        m = Int(NúmRegs * Rnd + 1)
        Get #1, m, Preg
        txtPregunta.Text = Preg.Pregunta
        lblResposta.Visible = True
        txtPregunta.Visible = True
        txtResposta.Visible = True
        txtResposta.Text = ""
    End If
End Sub

Private Sub Form_Load()
    Fitxer = "pregs.dat"
    Open Fitxer For Random As #1 Len = 512
    NúmRegs = LOF(1) / 512
    txtNúmRegistres = Str(NúmRegs)
    txtPregunta.Visible = False
    lblResposta.Visible = False
    txtResposta.Visible = False
    txtAvaluacióResposta.Visible = False
End Sub

Private Sub txtResposta_KeyDown(Keycode As Integer, Shift As Integer)
    Dim resp As String
    If Keycode = 13 Then
        txtAvaluacióResposta.Visible = True
        resp = txtResposta.Text
        If (RTrim$(Preg.Resposta) = resp) Then
             txtAvaluacióResposta.Text = "Molt bé"
         Else
             txtAvaluacióResposta.Text = "La resposta correcta és: " & Preg.Resposta
        End If
    End If
End Sub



Fitxer: m5p2ModB.BAS

Attribute VB_Name = "M5P2MODB"

Option Explicit

Type Preguntes
    Pregunta As String * 400
    Resposta As String * 112
End Type