Guia 2 de Ejercicios Visual Studio .Net

1. OBJETIVOS • Manejo de diferentes controles. • Programar objetos en diferentes eventos. • Utilización de variables de

Views 199 Downloads 8 File size 200KB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

1. OBJETIVOS • Manejo de diferentes controles. • Programar objetos en diferentes eventos. • Utilización de variables de memoria. • Estructuras de control: Condicional 1.1

CONSIDERACIONES INICIALES Debe crear un nuevo proyecto y realizar lo siguiente.

1.2 CREACIÓN DEL FORMULARIO (FrmCalificaciones.vb)

Se pide:

Se pide hallar el promedio y la puntuación de un aprendiz, según tres notas entre 0 y 5 ya que estas representan las calificaciones de un aprendiz del programa de formación: Programación de software. Promedio 6- 10 4– 5 0 –3

Puntuación A B C

Diseño del formulario: a) En el formulario inserte los controles necesarios desde el cuadro de Herramientas de Windows Form para obtener la siguiente apariencia:

NOTA_1:EL CONTR OL NUM ER I CUPDOW N Control que muestra una caja de texto con un valor numérico que podremos ir aumentando, disminuyendo al pulsar los botones para esta labor de que dispone el control. Un ejemplo para este control: Para ello deberás crear unProcedimiento para uno de éstoscontroles y escoger el EventoValueChanged Dim valor as Integer valor = NumericUpDown1.Value SELECT CASE valor CASE 5 To 10 NumericUpDown1.BackColor=Color.Gold CASE 10 To 20 NumericUpDown1.BackColor=Color.LimeGreen CASE ELSE NumericUpDown1.BackColor=NumericUpDown1.DefaultBackColor END SELECT

b) Ahora procedemos a establecer las Propiedades a los objetos, principalmente la propiedad (Name):

Objeto

Form1

Propiedad Name

Valor Asignado FrmCalificaciones

TextBox1 NumericUpDown1

NumericUpDown2

NumericUpDown3

TextBox2 TextBox3 Button1 Button2 Button3

Name Name MiniMum Maximum ReadOnly Name MiniMum Maximum ReadOnly Name MiniMum Maximum ReadOnly Name ReadOnly Name ReadOnly Name Name Name

txtAprendiz NumericUpDown1 0 10 True NumericUpDown2 0 10 True NumericUpDown3 0 10 True txtPromedio True txtPuntuacion True btnAceptar btnNuevo btnSalir

NOTA_2: Tener presente las siguientes observaciones:

EL MÉTODO PERFORMCLICK Éste método Genera/ Invoca el evento Click para un Botón

CUIDADO, AQUÍ HAY ERROR Dim 7Datos Dim Nombre+Grande Dim End

¿QUÉ ES UNA VARIABLE DE MEMORIA? Una variable es un dato temporal en memoria que tiene un nombre, un tipo de dato, un tiempo de vida y un alcance, los cuales lo dan la forma Como se declare ésta.

¿QUÉ ES LO QUE HACE LA FUNCIÓN STRCONV? Devuelve una cadena convertida según se ha especificado, siendo lo más utilizado para mayúsculas, minúsculas o la 1ra. En mayúsculas. Ejemplo: Dim texto as String texto=”josé ponce” StrConv(Texto, vbUpperCase) 'devuelve JOSÉ PONCE. StrConv(Texto, vbLowerCase) ‘devuelve josé ponce StrConv(Texto, vbProperCase) ‘devuelve José Ponce

FUNCIÓN VAL Devuelve los números contenidos en una cadena como un valor Numérico del tipo adecuado. Ejemplo: Dim vresp As Double ‘Devuelve 2457. vresp = Val("2457") ' Devuelve 2457. vresp = Val(" 2 45 7") ‘ Devuelve 24. vresp = Val("24 and 57")

¿CÓMO DECLARO UNA VARIABLE DE MEMORIA? La instrucción de declaración para Variables es Dim. Su ubicación y contenido determinan las Características de la variable. Ejemplo: Dim n1, n2 As Integer Dim x1, r1 As Long Dim v1, v2 As Byte, v3 As Date Dim prom As Double Dim sexo As Boolean Dim curso as String

¿POR QUÉ HAY ERROR? Una variable debe cumplir con las siguientes reglas:  Debe iniciar con un carácter Alfabético.  Debería contener solo caracteres alfabéticos, dígitos y carácter de subrayado.  El nombre no debe exceder a 255caracteres, etc.  Debe ser única en su alcance

c) Ahora proceda a escribir el código correspondiente a los objetos necesarios: PrivateSubFrmCalificaciones_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load ' Invoca / Ejecuta el Procedimiento BtnNuevo.Click Me.BtnNuevo.PerformClick() EndSub PrivateSub txtAprendiz_Leave(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtAprendiz.Leave txtAprendiz.Text = StrConv(txtAprendiz.Text, VbStrConv.Uppercase) EndSub

PrivateSub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click Dim N1 AsDouble, N2 AsDouble, N3 AsDouble Dim Promedio AsInteger N1 = NumericUpDown1.Value : N2 = NumericUpDown2.Value N3 = NumericUpDown3.Value Promedio = CInt((N1 + N2 + N3) / 3) txtPromedio.Text = Str(Promedio) If Promedio >= 6 And Promedio = 4 And Promedio = 0 And Promedio Maxsueldo Then MsgBox ("El avance no es permitido…") txtAvance.Text = "" txtAvance.Focus() EndIf EndSub PrivateSub rbtnCatA1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles rbtnCatA1.Click txtBonificacion.Text = Val(txtSueldo.Text) * 0.1 EndSub PrivateSub rbtnCatA2_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles rbtnCatA2.Click txtBonificacion.Text = Val(txtSueldo.Text) * 0.15 EndSub PrivateSub rbtnCatA3_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles rbtnCatA3.Click txtBonificacion.Text = Val(txtSueldo.Text) * 0.2 EndSub PrivateSub txtBonificacion_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBonificacion.TextChanged txtHonorarios.Text = Val(txtSueldo.Text) + Val(txtBonificacion.Text) EndSub PrivateSub chkIva_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkIva.CheckedChanged If chkIva.Checked = TrueThen txtIva.Text = Val(txtHonorarios.Text) * 0.1 Else txtIva.Text = 0 EndIf EndSub PrivateSub chkSena_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles chkSena.Click If chkSena.Checked = TrueThen txtSena.Text = Val(txtHonorarios.Text) * 0.07 Else txtSena.Text = 0 EndIf EndSub PrivateSub btnCalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcular.Click Dim desc AsDouble desc = Val(txtAvance.Text) + Val(txtSena.Text) + Val(txtIva.Text)

EndSub

txtNeto.Text = Val(txtHonorarios.Text) - desc

PrivateSub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click txtCodigo.Text = "" : txtApellidos.Text = "" txtNombres.Text = "" : txtSueldo.Text = "" txtAvance.Text = "" : txtBonificacion.Text = "" txtHonorarios.Text = "" : txtSena.Text = "" txtIva.Text = "" : txtNeto.Text = "" cboCargo.Text = "" rbtnCatA1.Checked = False : rbtnCatA2.Checked = False rbtnCatA3.Checked = False : chkSena.Checked = False chkIva.Checked = False : txtCodigo.Focus() EndSub PrivateSub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click Me.Close() EndSub