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

Fitxer: m3p2.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 frmLoto6_49 
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   Caption         =   "Loto 6/49"
   ClientHeight    =   4020
   ClientLeft      =   1755
   ClientTop       =   1515
   ClientWidth     =   2715
   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     =   4020
   ScaleWidth      =   2715
   Begin VB.TextBox txtElement 
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   24
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   675
      Left            =   600
      TabIndex        =   6
      Top             =   3120
      Width           =   1095
   End
   Begin VB.TextBox txtElementAVeure 
      Appearance      =   0  'Flat
      Height          =   375
      Left            =   2040
      TabIndex        =   5
      Top             =   2520
      Width           =   495
   End
   Begin VB.TextBox txtResultat 
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   375
      Left            =   120
      TabIndex        =   4
      Top             =   1920
      Width           =   2415
   End
   Begin VB.TextBox txtNúmeroEntrat 
      Appearance      =   0  'Flat
      Height          =   285
      Left            =   2160
      TabIndex        =   2
      Top             =   1440
      Width           =   375
   End
   Begin VB.TextBox txtInfo 
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   1215
      Left            =   120
      MultiLine       =   -1  'True
      TabIndex        =   0
      Top             =   120
      Width           =   2415
   End
   Begin VB.Label lblValors 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "Veure l'element:"
      ForeColor       =   &H80000008&
      Height          =   375
      Left            =   120
      TabIndex        =   3
      Top             =   2520
      Width           =   1815
   End
   Begin VB.Label lblInt 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "Introdueix un número:"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   120
      TabIndex        =   1
      Top             =   1440
      Width           =   1935
   End
End


Codi del programa. Programació de respostes a events

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

Option Explicit

Option Base 1

Dim VectorLoto(6)

Private Sub Form_Load()
    Dim i As Integer, j As Integer
    Dim NúmeroSortejat As Integer
    Dim Treballar As Integer, HaSortit As Integer
    txtInfo.Text = "Aquest programa fa un sorteig de sis números entre 1 i "
    txtInfo.Text = txtInfo.Text + "49. Has d'endevinar un d'aquests números."
    Randomize
    For i = 1 To 6
     Treballar = True
     Do While Treballar
        NúmeroSortejat = Int(Rnd * 49) + 1
        HaSortit = False
        For j = 1 To i - 1
            If NúmeroSortejat = VectorLoto(j) Then HaSortit = True
        Next j
        If Not HaSortit Then
            VectorLoto(i) = NúmeroSortejat
            Treballar = False
        End If
     Loop
    Next i
End Sub

Private Sub txtElementAVeure_Change()
    Dim i As Integer
    Dim Element As Integer
    i = Val(txtElementAVeure)
    If i > 0 And i < 7 Then
        Element = VectorLoto(i)
        txtElement = Str(Element)
    End If
End Sub

Private Sub txtNúmeroEntrat_KeyDown(keycode As Integer, Shift As Integer)
    Dim i As Integer
    Dim Endevinat As Integer
    
    If keycode = 13 Then
        Endevinat = False
        For i = 1 To 6
            If VectorLoto(i) = Val(txtNúmeroEntrat.Text) Then Endevinat = True
        Next i
        If Endevinat Then
            txtResultat.Text = "Molt bé"
        Else
            txtResultat.Text = "Intenta-ho altra vegada"
        End If
    End If
End Sub