Practica 1. Un primer contacte amb el Visual Basic
Práctica 2. Un paisatge i tres cares
Practica 3:Una petita aplicació per sumar
CALCULADORA
E2. Afegeix l'operació resta i l'operació quocient al formulari de l'exercici anterior.
Option Explicit
Private Sub cmdEsborrar_Click()
txtNumero1.Text = ""
txtNumero2.Text = ""
txtSumar.Text = ""
End Sub
Private Sub cmdMultiplicar_Click()
Dim n1 As Single 'Comentario se puede daclarar como global en General y así Dim n2 As Single
Dim multi As Single 'solo la declaro una vez
n1 = Val(txtNumero1.Text)
n2 = Val(txtNumero2.Text)
multi = n1 * n2
txtSumar.Text = Str$(multi)
End Sub
Private Sub cmdRestar_Click()
Dim n1 As Single
Dim n2 As Single
Dim Resta As Single
n1 = Val(txtNumero1.Text)
n2 = Val(txtNumero2.Text)
Resta = n1 - n2
txtSumar.Text = Str$(Resta)
End Sub
Private Sub cmdSumar_Click()
Dim n1 As Single
Dim n2 As Single
Dim Suma As Single
n1 = Val(txtNumero1.Text)
n2 = Val(txtNumero2.Text)
Suma = n1 + n2
txtSumar.Text = Str$(Suma)
End Sub
Private Sub cmdTancar_Click()
End
End Sub
Private Sub cmdDividir_Click()
Dim n1 As Single
Dim n2 As Single
Dim divi As Single
n1 = Val(txtNumero1.Text)
n2 = Val(txtNumero2.Text)
If n2 = 0 Then
txtSumar.Text = "No es pot dividir per 0"
Else
divi = n1 / n2
txtSumar.Text = Str$(divi)
End If
End Sub
Practica 4: Cronòmetre
Dim HoraInici As Date
Dim HoraAturada As Date
Private Sub cmdAturada_Click()
HoraAturada = Now
txtAturada.Text = Format(Now, "hh:mm:ss")
cmdAturada.Enabled = False
cmdInici.Enabled = True
txtTranscorregut = Format(HoraAturada - HoraInici, "hh:mm:ss")
txtSegonsTranscorreguts.Text = Hour(txtTranscorregut) * 3600 + Minute(txtTranscorregut) * 60 + Second(txtTranscorregut) & " segons"
End Sub
Private Sub cmdInici_Click()
HoraInici = Now
txtInici.Text = Format(Now, "hh:mm:ss")
cmdAturada.Enabled = True
cmdInici.Enabled = False
End Sub
Private Sub cmdTPCDia_Click()
'%Dia= SegundosParciales/ Segundos Totales"
txtTPCDia.Text = Format((Hour(Now) * 3600 + Minute(Now) * 60 + Second(Now)) / (CLng(24) * 3600), "0.00% del dia")
'24*3600 produeix desbordament, per aixo el convertim a long
End Sub