Está en la página 1de 11

EJERCICIOS RESUELTOS EN VISUAL BASIC 6.

0
H.A.F.
XIOMY VELAZQUES
UNA PUNO
1.- FUNCIONES MATEMATICAS

Private Sub Command1_Click()


Dim azar As Integer
Randomize
azar = Int(10 * Rnd) + 1
Label2.Caption = azar
End Sub
Private Sub Command2_Click()
Dim azar As Integer
Dim rangomenor As Integer
Dim rangomayor As Integer
Randomize
rangomayor = CInt(Text2)
rangomenor = CInt(Text1)
azar = Int((rangomayor - rangomenor + 1) * Rnd + rangomenor)
Label4 = azar
End Sub
Private Sub Command3_Click()
Dim numero As Integer
Dim raiz As Integer
raiz = CInt(Text3)
numero = CInt(Text4)
Label7.Caption = numero ^ (1 / raiz)
Label7.Caption = Round(Label7, 4)
End Sub
Private Sub Command4_Click()
Dim numero

Dim decimales As Integer


numero = Text5
decimales = CInt(Text6)
Label10.Caption = Round(numero, decimales)
End Sub
Private Sub Command5_Click()
End
End Sub

2.- CALCULADORA

Private Sub cdm_salir_Click()


End
End Sub
Private Sub cmd_nuevo_Click()
txt_n1.Text = " "
txt_n2.Text = " "
txt_res.Text = " "
lblOp.Caption = " "
End Sub
Private Sub opt_div_Click()
If txt_n1.Text = "" Then
MsgBox "Debe ingresar un numero"
txt_n1.SetFocus
Exit Sub
End If

If txt_n2.Text = "" Then


MsgBox "Debe ingresar un numero"
txt_n2.SetFocus
Exit Sub
End If
txt_res.Text = Val(txt_n1.Text) / Val(txt_n2.Text)
lblOp.Caption = "/"
End Sub
Private Sub opt_mul_Click()
If txt_n1.Text = "" Then
MsgBox "Debe ingresar un numero"
txt_n1.SetFocus
Exit Sub
End If
If txt_n2.Text = "" Then
MsgBox "Debe ingresar un numero"
txt_n2.SetFocus
Exit Sub
End If
txt_res.Text = Val(txt_n1.Text) * Val(txt_n2.Text)
lblOp.Caption = "*"
End Sub
Private Sub opt_raiz_Click()
If txt_n1.Text = "" Then
MsgBox "Debe ingresar un numero"
txt_n1.SetFocus
Exit Sub
End If
txt_res.Text = Sqr(txt_n1.Text)
End Sub
Private Sub opt_res_Click()
If txt_n1.Text = "" Then
MsgBox "Debe ingresar un numero"
txt_n1.SetFocus
Exit Sub
End If
If txt_n2.Text = "" Then
MsgBox "Debe ingresar un numero"
txt_n2.SetFocus
Exit Sub
End If
txt_res.Text = Val(txt_n1.Text) - Val(txt_n2.Text)
lblOp.Caption = "-"
End Sub
Private Sub opt_sum_Click()
If txt_n1.Text = "" Then
MsgBox "Debe ingresar un numero"
txt_n1.SetFocus

Exit Sub
End If
If txt_n2.Text = "" Then
MsgBox "Debe ingresar un numero"
txt_n2.SetFocus
Exit Sub
End If
txt_res.Text = Val(txt_n1.Text) + Val(txt_n2.Text)
lblOp.Caption = "+"
End Sub

3.- EDAD

Private Sub cmdAceptar_Click()


Dim FecNac As Date, Edad As Integer
FecNac = CDate(txtFecNac)
Edad = CInt((Date - FecNac) / 365)
txtEdad = Str(Edad) & "aos"
End Sub
Private Sub cmdLimpiar_Click()
txtFecNac.Text = " "
txtEdad.Text = " "
End Sub
Private Sub cmdSalir_Click()
End
End Sub

4.- REA Y PERMETRO DE UN TRIANGULO

rivate Sub cmdLim_Click()


txt_n1.Text = " "
txt_n2.Text = " "
txt_n3.Text = " "
txt_res.Text = " "
End Sub
Private Sub cmdSal_Click()
End
End Sub
Private Sub opt_area_Click()
Dim A, B, C, Area, Perimetro, S As Single
A = txt_n1.Text
B = txt_n2.Text
C = txt_n3.Text
If A > 0 And B > 0 And C > 0 And C < Val(A) + Val(B) And A < Val(C) + Val(B) And B <
Val(A) + Val(C) Then
S = (Val(A) + Val(B) + Val(C)) / 2
txt_res.Text = Sqr(Val(S) * ((Val(S) - Val(A)) * (Val(S) - Val(B)) * (Val(S) - Val(C))))
Else
MsgBox "Datos no vlidos"
End If
End Sub
Private Sub opt_per_Click()
Dim A, B, C, Area, Perimetro, S As Single
A = txt_n1.Text
B = txt_n2.Text
C = txt_n3.Text
txt_res.Text = Val(A) + Val(B) + Val(C)
End Sub
5.- IMAGINA QUE LO QUE QUEREMOS AHORA ES QUE EL ORDENADOR NOS
DEVUELVA, MIRANDO LA EDAD QUE INTRODUCIMOS, SI ES MENOR DE 10

AOS, SI TIENE ENTRE 10 Y 20 AOS, SI TIENE ENTRE 20 Y 30 AOS O SI ES


MAYOR DE 30.

Private Sub cmdCal_Click()


If Val(txtEdad.Text) < 10 Then
cmdCom.Caption = " Menos de 10 aos "
Else
If Val(txtEdad.Text) < 20 Then
cmdCom.Caption = " Entre 10 y 20 aos "
Else
If Val(txtEdad.Text) < 30 Then
cmdCom.Caption = " Entre 20 y 30 aos "
Else
cmdCom.Caption = " Mas de 30 aos "
End If
End If
End If
End Sub
Private Sub cmdLimp_Click()
txtEdad.Text = " "
cmdCom.Caption = " "
End Sub
Private Sub cmdSal_Click()
End
End Sub

5.1.- Utilizando Select Case

Private Sub cmdCal_Click()


Select Case Val(txtEdad.Text)
Case Is < 10
cmdCom.Caption = "Menos de 10 aos"
Case Is < 20
cmdCom.Caption = "Entre 10 y 20 aos"
Case Is < 30
cmdCom.Caption = "Entre 20 y 30 aos"
Case Else
cmdCom.Caption = "mas de 30 aos"
End Select
End Sub
Private Sub cmdLimp_Click()
txtEdad.Text = " "
cmdCom.Caption = " "

End Sub
Private Sub cmdSal_Click()
End
End Sub
6.- RESTAURANTE

Private Sub cmdAceptar_Click()


Dim Hamburguesa As Integer, Cerveza As Integer
Dim Gaseosa As Integer, Ensalada As Integer
Dim Salchichas As Integer, Refresco As Integer
Dim Sopa As Integer, Postre As Integer
Dim VentaTotal As Double, Impuesto As Double
Hamburguesa = Val(txtHam)
Cerveza = Val(txtCer)
Gaseosa = Val(txtGas)
Ensalada = Val(txtEns)
Salchichas = Val(txtSal)
Refresco = Val(txtRef)
Sopa = Val(txtSop)
Postre = Val(txtPos)
VentaTotal = Hamburguesa * 2.5 + Cerveza * 4 _
+ Gaseosa * 3 + Ensalada * 1.5 + Salchichas * 2 _
+ Refresco * 1 + Sopa * 1.5 + Postre * 1.5
Impuesto = 0.18 * VentaTotal
txtVen = Str(VentaTotal)
txtImp = Str(Impuesto)
End Sub
Private Sub cmdLimpiar_Click()
txtHam = " ": txtCer = " "
txtGas = " ": txtEns = " "
txtSal = " ": txtRef = " "
txtSop = " ": txtPos = " "
txtVen = " ": txtImp = " "
txtHam.SetFocus
End Sub
Private Sub cmdSalir_Click()
End
End Sub

Private Sub Form_Load()


GrdMenu.Cols = 2
GrdMenu.Rows = 9
GrdMenu.FixedCols = 0
GrdMenu.FixedRows = 1
GrdMenu.TextArray(0) = "Men"
GrdMenu.TextArray(1) = "Precio"
GrdMenu.TextArray(2) = "Hamburguesa"
GrdMenu.TextArray(3) = "2.50"
GrdMenu.TextArray(4) = "Cerveza"
GrdMenu.TextArray(5) = "4.00"
GrdMenu.TextArray(6) = "Gaseosa"
GrdMenu.TextArray(7) = "3.00"
GrdMenu.TextArray(8) = "Ensalada"
GrdMenu.TextArray(9) = "1.50"
GrdMenu.TextArray(10) = "Salchichas"
GrdMenu.TextArray(11) = "2.00"
GrdMenu.TextArray(12) = "Refresco"
GrdMenu.TextArray(13) = "1.00"
GrdMenu.TextArray(14) = "Sopa"
GrdMenu.TextArray(15) = "1.50"
GrdMenu.TextArray(16) = "Postre"
GrdMenu.TextArray(17) = "1.50"
End Sub

7.- COSTO TOTAL DEL AGUA

Private Sub cmdAce_Click()


Dim Puno As Double, Acora As Double
Dim Plateria As Double, Laraqueri As Double
Dim Huata As Double, Coata As Double
Dim Atuncolla As Double, Paucarcolla As Double
Dim Vilque As Double, Maazo As Double
Dim Tiquillaca As Double, SanAntonio As Double
Dim Chucuito As Double
Dim CostoTotal As Double, VolumenTotal As Double
Dim Alta As Double
Puno = Val(txtPun)
Acora = Val(txtAco)
Plateria = Val(txtPla)
Laraqueri = Val(txtLar)
Huata = Val(txtHua)
Coata = Val(txtCoa)
Atuncolla = Val(txtAtu)
Paucarcolla = Val(txtPau)
Vilque = Val(txtVil)
Maazo = Val(txtMa)
Tiquillaca = Val(txtTiq)
SanAntonio = Val(txtSan)
Chucuito = Val(txtChu)
CostoTotal = Puno * 5.5 + Acora * 5 + Plateria * 4 + Laraqueri * 1.5 _
+ Huata * 3 + Coata * 3 + Atuncolla * 3.5 + Paucarcolla * 4.5 _
+ Vilque * 3 + Maazo * 2 + Tiquillaca * 2.5 + SanAntonio * 2 _
+ Chucuito * 2.5
VolumenTotal = Val(txtPun.Text) + Val(txtAco.Text) + Val(txtPla.Text) + Val(txtLar.Text)
+ Val(txtHua.Text) _
+ Val(txtCoa.Text) + Val(txtAtu.Text) + Val(txtPau.Text) + Val(txtVil.Text) _
+ Val(txtMa.Text) + Val(txtTiq.Text) + Val(txtSan.Text) + Val(txtChu.Text)

txtCosto = Str(CostoTotal)
txtVol = Str(VolumenTotal)
Alta = VolumenTotal / 0.2
If Alta < 10000 Then
cmdCom.Caption = " Hay mas de 2,000 Habitantes "
Else
If Alta < 50000 Then
cmdCom.Caption = " Hay mas de 10,000 Habitantes "
Else
cmdCom.Caption = " Hay mas de 50,000 Habitantes "
End If
End If
End Sub
Private Sub cmdLim_Click()
txtPun = " ": txtAco = " "
txtPla = " ": txtLar = " "
txtHua = " ": txtCoa = " "
txtAtu = " ": txtPau = " "
txtVil = " ": txtMa = " "
txtTiq = " ": txtSan = " "
txtChu = " ": txtCosto = " "
txtVol = " ":
txtPun.SetFocus
cmdCom.Caption = " "
End Sub
Private Sub cmdSal_Click()
End
End Sub
Private Sub Form_Load()
grdDis.Cols = 2
grdDis.Rows = 14
grdDis.FixedCols = 0
grdDis.FixedRows = 1
grdDis.TextArray(0) = "Distrito"
grdDis.TextArray(1) = "Precio d Agua"
grdDis.TextArray(2) = "Puno"
grdDis.TextArray(3) = "5.50"
grdDis.TextArray(4) = "Acora"
grdDis.TextArray(5) = "5.00"
grdDis.TextArray(6) = "Plateria"
grdDis.TextArray(7) = "4.00"
grdDis.TextArray(8) = "Laraqueri"
grdDis.TextArray(9) = "1.50"
grdDis.TextArray(10) = "Huata"
grdDis.TextArray(11) = "3.00"
grdDis.TextArray(12) = "Coata"
grdDis.TextArray(13) = "3.00"
grdDis.TextArray(14) = "Atuncolla"
grdDis.TextArray(15) = "3.50"
grdDis.TextArray(16) = "Paucarcolla"
grdDis.TextArray(17) = "4.50"
grdDis.TextArray(18) = "Vilque"
grdDis.TextArray(19) = "3.00"
grdDis.TextArray(20) = "Maazo"

grdDis.TextArray(21)
grdDis.TextArray(22)
grdDis.TextArray(23)
grdDis.TextArray(24)
grdDis.TextArray(25)
grdDis.TextArray(26)
grdDis.TextArray(27)

=
=
=
=
=
=
=

grdPob.Cols = 2
grdPob.Rows = 4
grdPob.FixedCols = 0
grdPob.FixedRows = 1
grdPob.TextArray(0) =
grdPob.TextArray(1) =
grdPob.TextArray(2) =
grdPob.TextArray(3) =
grdPob.TextArray(4) =
grdPob.TextArray(5) =
grdPob.TextArray(6) =
grdPob.TextArray(7) =
End Sub

"2.00"
"Tiquillaca"
"2.50"
"SanAntonio"
"2.00"
"Chucuito"
"2.50"

"POBLACION"
"DOTACION l/hab/dia"
"Baja"
"120"
"Media"
"150"
"Alta"
"200"

También podría gustarte