

Fitxer: m2p2.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 Form1
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Gestió d'una llista"
ClientHeight = 3720
ClientLeft = 1275
ClientTop = 1380
ClientWidth = 5685
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 = 3720
ScaleWidth = 5685
Begin VB.TextBox txtNúmero
Appearance = 0 'Flat
Height = 375
Left = 4080
TabIndex = 12
Top = 3000
Width = 975
End
Begin VB.TextBox txtLloc
Appearance = 0 'Flat
Height = 375
Left = 1560
TabIndex = 10
Top = 3000
Width = 735
End
Begin VB.TextBox txtValorIntroduit
Appearance = 0 'Flat
Height = 375
Left = 2040
TabIndex = 8
Top = 120
Width = 855
End
Begin VB.ListBox lstAlçades
Appearance = 0 'Flat
Height = 1980
Left = 3000
TabIndex = 7
Top = 120
Width = 2415
End
Begin VB.TextBox txtMitjana
Appearance = 0 'Flat
Enabled = 0 'False
Height = 375
Left = 3840
TabIndex = 6
Top = 2280
Width = 1575
End
Begin VB.CommandButton cmdMitjana
Appearance = 0 'Flat
Caption = "&Calcula la mitjana"
Height = 375
Left = 1440
TabIndex = 5
Top = 2280
Width = 2295
End
Begin VB.CommandButton cmdFí
Appearance = 0 'Flat
Caption = "&Fí"
Height = 375
Left = 240
TabIndex = 4
Top = 2280
Width = 975
End
Begin VB.CommandButton cmdEsborraLlista
Appearance = 0 'Flat
Caption = "&Esborra la llista"
Height = 375
Left = 240
TabIndex = 3
Top = 1800
Width = 2535
End
Begin VB.CommandButton cmdEsborraElement
Appearance = 0 'Flat
Caption = "E&sborra l'element assenyalat"
Height = 375
Left = 240
TabIndex = 2
Top = 1320
Width = 2535
End
Begin VB.CommandButton cmdAfegeix
Appearance = 0 'Flat
Caption = "&Inclou el valor a la llista"
Height = 375
Left = 240
TabIndex = 1
Top = 840
Width = 2535
End
Begin VB.Label lblInNúmero
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Número:"
ForeColor = &H80000008&
Height = 375
Left = 3000
TabIndex = 11
Top = 3000
Width = 975
End
Begin VB.Label lblInLloc
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Lloc:"
ForeColor = &H80000008&
Height = 255
Left = 840
TabIndex = 9
Top = 3000
Width = 615
End
Begin VB.Label lblnValor
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Introdueix un valor:"
ForeColor = &H80000008&
Height = 375
Left = 240
TabIndex = 0
Top = 240
Width = 1695
End
End
Codi del programa. Programació de respostes a events
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const MB_ICONEXCLAMATION = 48, MB_YESNO = 4, IDYES = 6
Private Sub cmdAfegeix_Click()
If txtValorIntroduit <> "" Then
lstAlçades.AddItem txtValorIntroduit
txtValorIntroduit.Text = ""
End If
End Sub
Private Sub cmdEsborraElement_Click()
If lstAlçades.ListIndex >= 0 Then
lstAlçades.RemoveItem lstAlçades.ListIndex
End If
End Sub
Private Sub cmdEsborraLlista_Click()
Dim Contestació, RegDef As Integer
Dim Missatge, Títol As String
Missatge = "Voleu esborrar tots els elements de la llista?"
RegDef = MB_ICONEXCLAMATION + MB_YESNO
Títol = "Atenció"
Contestació = MsgBox(Missatge, RegDef, Títol)
If Contestació = IDYES Then lstAlçades.Clear
End Sub
Private Sub cmdFí_Click()
End
End Sub
Private Sub cmdMitjana_Click()
Dim Total As Single
Dim Actual As Integer
Total = 0
Actual = 0
Do While Actual < lstAlçades.ListCount
Total = Total + Val(lstAlçades.List(Actual))
Actual = Actual + 1
Loop
If lstAlçades.ListCount > 0 Then
txtMitjana = Format(Total / lstAlçades.ListCount, "0.00")
End If
End Sub
Private Sub txtLloc_Change()
Dim Index As Integer
Index = Val(txtLloc)
If lstAlçades.ListCount > Index Then
txtNúmero = lstAlçades.List(Val(txtLloc))
End If
End Sub
Private Sub txtValorIntroduit_KeyPress(keyascii As Integer)
If keyascii = 13 Then cmdAfegeix_Click
End Sub