Calcular El Area Del Triangulo Visual Basic 6

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 7

Calcular el area del triangulo Visual Basic 6.

CALCULAR EL AREA DEL TRIANGULO

PRIMER PASO EL DISEO

PROPIEDADES

Control

Propiedad

Valor

Label1

(Nombre)

LblBase

Caption

Ingrese la base :

(Nombre)

LblAltura

Caption

Ingrese la altura :

(Nombre)

LblArea

Caption

El area del triangulo es :

(Nombre)

TxtBase

Text

(Vacio)

(Nombre)

TxtAltura

Caption

(Vacio)

(Nombre)

TxtArea

Caption

(Vacio)

(Nombre)

CmdCalcular

Caption

Calcular

(Nombre)

CmdLimpiar

Caption

Limpiar

(Nombre)

CmdCerrar

Caption

Cerrar

Label2
Label3
TextBox1
TextBox2
TextBox3
Command1
Command2
Command3

CODIGO FUENTE

Private Sub CmdCalcular_Click()


TxtArea.Text = (Val(TxtBase.Text) * Val(TxtAltura.Text)) / 2
End Sub
Private Sub CmdCerrar_Click()
Unload Me
End
End Sub
Private Sub CmdLimpiar_Click()
TxtBase.Text = ""
TxtAltura.Text = ""
TxtArea.Text = ""
TxtBase.SetFocus
End Sub

. PROGRAMA DE PRACTICA

Calcular el area del cuadrado,circulo y triangulo donde el usuario elija por medio de option
button y cada boton le diga que tenga que hacer para la operacion. El resultado es claro que debe ser
en una caja de texto.
1. PLANEACION
*Calcular el rea del circulo, rectngulo y triangulo por medio de option button.
*Mostrar el resultado en una caja de texto.
*Necesitamos 3 cajas de texto, 2 label, 1 frame, 3 optiond button y 3 comandbutton donde
calcularemos
1.1 LISTA DE CHEQUEO:
*Declarar variables
*Darles Valor
*Operar
*Mostrar resultado
2. INTERFAZ GRAFICA

Cuando le damos iniciar a nuestra aplicacion los comand de


calcular deben de aparecer solamente uno para el usuario. para esto utilisamos la propiedad visible
=true :
3.PROGRAMACION DE EVENTOS:
primero colocamos todos los controles con la propiedad visible= false y debemos cambiarle el
nombre a los tres comand de calcular por triangulo, cuadrado, y circulo. para mayor comodidad al
programar. En el option 1 escribimos el siguiente codigo :
Private Sub Option1_Click()
Option1.Value = False
CUADRADO.Visible = True
Label1.Visible = True
Text1.Visible = True

Text3.Visible = True
Label1.Caption = "ingrese lado"
TRIANGULO.Visible = False
CIRCULO.Value = False
Label2.Visible = False
Text2.Visible = False
End Sub
como podemos ver ocultamos los dos comandbutton de calcular que no utilizaremos y el label 2 y
text2.
en el option 2 escribimos el siguiente codigo
Private Sub Option2_Click()
Option2.Value = False
TRIANGULO.Visible = True
Label1.Visible = True
Label2.Visible = True
Text1.Visible = True
Text2.Visible = True
Text3.Visible = True
Label1.Caption = "INGRESE BASE"
Label2.Caption = "INGRESE ALTURA"
CUADRADO.Visible = False
CIRCULO.Value = False
End Sub
En este solo ocultamos los dos comand de calcular.
el otro option button tendras que hacer el codigo. en los comand de calcular haremos la formula de
cada area como por ejemplo.
Private Sub CUADRADO_Click()
A = Text1.Text
RES = A * A
Text3.Text = RES

End Sub
Private Sub TRIANGULO_Click()
B = Text1.Text
A = Text2.Text
RES = B * A / 2
Text3.Text = RES
End Sub
Private Sub CIRCULO_Click()
RADIO = Text1.Text AC = PI * (RADIO * RADIO)
Text3.Text = AC
End Sub
y en general :
Const PI As Double = 3.1416
Dim RADIO As Double
Dim AC As Double
Dim A As Double
Dim B As Double
Dim RES As Double

CALCULAR EL AREA DEL CIRCULO

Private Sub Command1_Click()


Text3.Text = Val(3.1416) * Val(Text2.Text) * Val(Text2.Text)
End Sub

Private Sub Command2_Click()


Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text1.SetFocus
End Sub

Private Sub Command3_Click()


End
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)


If KeyAscii <> 57 Then
KeyAscii = 0
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)


If KeyAscii <> 57 Then
KeyAscii = 0
End If

End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)


If KeyAscii <> 57 Then
KeyAscii = 0
End If
End Sub
Text1.Text = Text1.Text
Text2.Text = Val(Text1.Text) * 3.1416 ^ 2
(Colocamos "* 3.1416" porque el area de un circulo se calcula asi: Radio por Pi elevado al
cuadrado).
Despus le damos doble click en "Borrar" y nos aparece lo siguiente:
"Private Sub Command2_Click ()"
debajo de eso escribimos lo siguiente:
Text1.Text = ""
Text2.Text = ""
Despus de esto le damos doble click en "Salir" y nos aparece :
"Private Sub Command3_Click()"
debajo de esto escribimos:
"End"
y lo prueban y LISTO!!!!!!!! ya esta hecho el programa para calcular el area de un circulo.
Aqui los procedimientos

También podría gustarte