Vb lab2

7
Lenguaje de Programación Visual Basic Laboratorio 2 Objetivos: Al término del laboratorio el estudiante debe ser capaz de: Conocer y utilizar controles básicos para el diseño de una aplicación. Aplicación 1 Generar una aplicación en Visual Basic que nos permita ingresar un usuario y la clave secreta respectiva. Ingresar a VB. Crear un nuevo proyecto, insertar en el formulario los siguientes controles: Frame1, Image1 Label1, Label2, Label3, Text1, Tex2, Command1 y Command2. Cambiar las propiedades: Control Propiedad Valor Form1 Name frmLogin Caption Inicio Frame1 Caption Inicio de Sesión Label1 Caption Ingrese su nombre y contraseña Alignment 2 Center Font Arial, negrita cursiva, tamaño 10 Label2 Caption &Usuario Label3 Caption &Contraseña Text1 Text “” Text2 Text “” PasswordChar * Command1 Caption &Aceptar Command2 Caption C&ancelar Image1 Picture c:\.....\vb98\bmp\dibujo.ico

Transcript of Vb lab2

Page 1: Vb lab2

Lenguaje de Programación – Visual Basic

LLaabboorraattoorriioo 22 Objetivos:

Al término del laboratorio el estudiante debe ser capaz de:

Conocer y utilizar controles básicos para el diseño de una aplicación.

Aplicación 1 Generar una aplicación en Visual Basic que nos permita ingresar un usuario y la

clave secreta respectiva. Ingresar a VB.

Crear un nuevo proyecto, insertar en el formulario los siguientes controles: Frame1, Image1

Label1, Label2, Label3, Text1, Tex2, Command1 y Command2.

Cambiar las propiedades:

Control Propiedad Valor

Form1 Name frmLogin Caption Inicio Frame1 Caption Inicio de Sesión Label1 Caption Ingrese su nombre y contraseña Alignment 2 – Center Font Arial, negrita cursiva, tamaño 10 Label2 Caption &Usuario Label3 Caption &Contraseña Text1 Text “” Text2 Text “” PasswordChar * Command1 Caption &Aceptar

Command2 Caption C&ancelar

Image1 Picture c:\.....\vb98\bmp\dibujo.ico

Page 2: Vb lab2

Lenguaje de Programación – Visual Basic

2

El resultado debe quedar de la siguiente manera:

Ingresamos el código para la aplicación:

Private Sub Command1_Click()

MsgBox "Bienvenido " & Text1.Text, 0 + vbExclamation

End

End Sub

Private Sub Command2_Click()

End

End Sub

Cuando se realice un clic en el botón Aceptar, se muestra un mensaje de bienvenida con el

nombre del usuario.

Pruebe los siguientes mensajes:

Msgbox “Hola, bienvenido al sistema” & Text1.text ,0+VbInformation

Msgbox “Que tal ” & Text1.text, 0 +VbInformation

Page 3: Vb lab2

Lenguaje de Programación – Visual Basic

3

Aplicación 2 Cálculo del promedio y la condición de un alumno

Abrir un nuevo proyecto en VB

En el formulario insertar los siguientes controles.

Cambiar las propiedades:

Objeto Propiedad Valor

Form1 Name frmEvaluacion

Caption Evaluación

Text1 Maxlength 8

Label10 Caption “”

Appearance 0 – Flat

BorderStyle 1 – Fixed Single

Cambiar las demás propiedades para obtener el diseño del formulario como indica la siguiente

figura:

Page 4: Vb lab2

Lenguaje de Programación – Visual Basic

4

Ingresar el código para la aplicación:

Private Sub Command1_Click()

Dim nota1, nota2, nota3, prom As Double

nota1 = Val(Text5.Text)

nota2 = Val(Text6.Text)

nota3 = Val(Text7.Text)

prom = (nota1 + nota2 + nota3) / 3

Text8.Text = Round(prom, 2)

If prom > 10.5 Then

Label10.Caption = "Aprobado"

Else

Label10.Caption = "Desaprobado"

End If

End Sub

Private Sub Command2_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

Text5.Text = ""

Text6.Text = ""

Text7.Text = ""

Text8.Text = ""

Label10.Caption = ""

Text1.SetFocus

End Sub

Private Sub Command3_Click()

End

End Sub

Page 5: Vb lab2

Lenguaje de Programación – Visual Basic

5

Ejecute el formulario:

Explique el código de la aplicación:

Text8.Text = Round(prom, 2) ………………………………………………

If prom > 10.5 Then ………………………………………………

Label10.Caption = "Aprobado" ………………………………………………

Else ………………………………………………

Label10.Caption = "Desaprobado" ………………………………………………

End If ………………………………………………

Aplicación 3

Realizar una aplicación que halle las raíces de la ecuación cuadrática:

ax2+bx+c=0

Se sabe que las raíces son:

a

acbbx

2

42

Abrir un nuevo proyecto en VB e inserte los siguientes controles:

Page 6: Vb lab2

Lenguaje de Programación – Visual Basic

6

Cambiar las propiedades para obtener la siguiente interfaz:

Ingresar el código para la aplicación:

Private Sub Command1_Click()

Dim a, b, c, d, x1, x2 As Double

a = Val(Text1.Text)

b = Val(Text2.Text)

c = Val(Text3.Text)

If a <> 0 Then

d = b * b - 4 * a * c

If d > 0 Then

x1 = (-b + Sqr(d)) / (2 * a)

x2 = (-b - Sqr(d)) / (2 * a)

Text4.Text = x1

Text5.Text = x2

Else

MsgBox "Tiene solucion imaginaria", 0 + vbExclamation

Text4.Text = ""

Page 7: Vb lab2

Lenguaje de Programación – Visual Basic

7

Text5.Text = ""

End If

Else

MsgBox "El valor de a debe ser diferente de cero", 0 + vbCritical

Text4.Text = ""

Text5.Text = ""

End If

End Sub

Private Sub Command2_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

Text5.Text = ""

End Sub

Private Sub Command3_Click()

End

End Sub

Ejercicio :

Realizar una aplicación en Visual Basic que halle las funciones trigonométricas de un ángulo in-

gresado por el usuario. Utilice las siguientes funciones: sin, cos y tan