Practica 1 Taller de Programacion Vb Net

22
Ing. Hobby Saavedra Rosas Visual Basic .Net PRÁCTICA I: TALLER DE PROGRAMACIÓN VISUAL BASIC .NET 1. EJERCICIO 01: Ingresar una serie de números enteros y determinar la cantidad de pares, impares y la suma total de todos los datos. 2. EJERCICIO-02 Ingrese una serie de números enteros, y si es entero sea añadido a la lista de pares, en caso contrario se agregue a la lista de impares, además se debe agregar todos los números en la lista total de números.

Transcript of Practica 1 Taller de Programacion Vb Net

Page 1: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

PRÁCTICA I: TALLER DE PROGRAMACIÓN VISUAL BASIC .NET

1. EJERCICIO 01:

Ingresar una serie de números enteros y determinar la cantidad de pares,

impares y la suma total de todos los datos.

2. EJERCICIO-02

Ingrese una serie de números enteros, y si es entero sea añadido a la lista de pares, en

caso contrario se agregue a la lista de impares, además se debe agregar todos los números

en la lista total de números.

Page 2: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

3. EJERCICIO-03

Ejercicio que me permite el ingreso de hinchas por medio de los botones y cuenta los el total tanto

de Real Madrid y Barcelona.

Public Class Frmejercicio_03 'DECLARACIÓN DE VARIABLES GLOBALES(A NIVEL DE FORMULARIO) 'cantidad de hinchas real madrid Dim hinchasRM As Integer 'cantidad de hinchas barcelona Dim hinchasBar As Integer 'Vector para almacenar los equipos Dim Equipos() As String 'suma la cantidad total de hinchas del real madrid Dim sumaRealMadri As Integer 'suma la cantidad total de hinchas del barcelona Dim sumaBarcelona As Integer Private Sub Frmejercicio_03_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'asignamos los valores de los equipos en el arreglo equipos Equipos = {"<Seleccione>", "Real Madrid", "Barcelona"} 'cargamos el vector equipos al combobox cboEquipos cboEquipos.Items.AddRange(Equipos) 'seleccionamos el elemento que deseamos mostrar en el combobox cboEquipos 'al iniciar el formulario cboEquipos.SelectedIndex = 0 End Sub 'Procedimiento (No devuelve ningun valor, solo ejecuta la instrucciones) 'Permite agregar hinchas a un determinado equipo (Listbox) ' LstRealMadrid o LstBarcelona Sub AgregarHinchasAEquipos() 'Vericamos a que equipo pertenecen los hinchas y lo agregamos a su respectivo equipo If IsNumeric(txtCantHinchas.Text) Then

Page 3: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

If cboEquipos.Text = "Real Madrid" Then 'Agregamos hinchas al listbox de RM lsbRealMadrid.Items.Add(Me.txtCantHinchas.Text) 'Limpiamos el contenido de la caja de texto txtCantHinchas txtCantHinchas.Clear() ElseIf cboEquipos.Text = "Barcelona" Then lsbBarcelona.Items.Add(Me.txtCantHinchas.Text) txtCantHinchas.Clear() Else MsgBox("Seleccione su equipo") End If Else MsgBox("Ingrese solo números") End If End Sub Sub Limpiar() If lsbBarcelona.Items.Count > 0 Then lsbBarcelona.Items.Clear() lsbRealMadrid.Items.Clear() cboEquipos.SelectedIndex = 0 Else MsgBox("No hay datos para limpiar") End If End Sub 'Declaramos una función (Devuelve un valor del tipo de dato que corresponde) Private Function ReportarSuma(ByVal equipo As ListBox) As Integer Dim suma, i As Integer For i = 0 To equipo.Items.Count - 1 suma = suma + Val(equipo.Items.Item(i)) Next Return suma End Function Sub ReporteDeDatos() Dim porcB, porcRM As Double Dim cantTotal As Integer sumaBarcelona = ReportarSuma(lsbBarcelona) txtBarcelona.Text = sumaBarcelona sumaRealMadri = ReportarSuma(lsbRealMadrid) txtRmadrid.Text = sumaRealMadri 'Calculamos la cantidad total de hinchas cantTotal = sumaBarcelona + sumaRealMadri 'Calcular el procentaje de hinchas de barcelona porcB = sumaBarcelona / cantTotal Me.txtPromBarcelona.Text = FormatPercent(porcB) 'Calcular el porcentaje de hinchas de real madrid porcRM = sumaRealMadri / cantTotal Me.txtPromReal.Text = FormatPercent(porcRM) End Sub Sub EliminarElementos() If lsbBarcelona.Items.Count > 0 Then lsbRealMadrid.Items.RemoveAt(lsbRealMadrid.SelectedIndex) ReporteDeDatos() Else MsgBox("No hay Datos para eliminar") End If End Sub

Page 4: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click AgregarHinchasAEquipos() End Sub Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click Limpiar() End Sub Private Sub btnReportar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReportar.Click ReporteDeDatos() End Sub Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorrar.Click EliminarElementos() End Sub End Class

4. EJERCICIO-04 Permite el ingreso de nombre sueldo categoría y permite calcular el descuento.

Public Class FrmEjercicio_04 Dim sueldoBrutoEmp, descuentoEmp, valIGVEmp, sueldoNetoEmp, bonoEmp As Double Dim datos As String() Dim opcion As String Dim tipoDsto As String

Page 5: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click AgregarDatos() habilitarEntradas(False) configurarDataGridView() End Sub Sub AgregarDatos() datos = {txtEmpleado.Text, cboCategoria.Text, nudHijos.Value.ToString, opcion, tipoDsto, descuentos.ToString, bonificacionEmpleado.ToString, FormatCurrency(sueldoBrutoEmpleado.ToString), calcularIGV.ToString, calcularSueldoNeto.ToString} dgvEmpleados.Rows.Add(datos) End Sub Function categoriaEmpleado() As Double Dim index As Integer Dim sueldoBas As Double index = cboCategoria.SelectedIndex Select Case index Case 1 sueldoBas = 750 Case 2 sueldoBas = 700 Case 3 sueldoBas = 650 Case Else sueldoBas = 0 End Select Return sueldoBas End Function Function bonoEstadoCivil() As Double Dim bonoEstCivil As Double If rbtCasado.Checked = True Then bonoEstCivil = 50 Else bonoEstCivil = 25 End If Return bonoEstCivil End Function Function descuentos() As Double Dim valDscto As Double If rbtAfp.Checked = True Then valDscto = 0.1 * categoriaEmpleado() ElseIf rbtFnp.Checked = True Then valDscto = 0.08 * categoriaEmpleado() ElseIf rbtEsSalud.Checked = True Then valDscto = 0.05 * categoriaEmpleado() End If Return valDscto End Function Function bonificacionEmpleado() As Double Dim bono As Double bono = bonoEstadoCivil() + CDbl(nudHijos.Value) * 50 Return bono End Function Function sueldoBrutoEmpleado() As Double Dim sueldoB As Double sueldoB = categoriaEmpleado() + bonificacionEmpleado() Return sueldoB

Page 6: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

End Function Function calcularIGV() As Double Dim valorIGV As Double Static igv As Double = 0.18 valorIGV = igv * sueldoBrutoEmpleado() Return valorIGV End Function Function calcularSueldoNeto() As Double Dim sueldoNeto As Double sueldoNeto = sueldoBrutoEmpleado() - descuentos() - calcularIGV() Return sueldoNeto End Function Sub CalcularDatosEmpleado() txtBono.Text = FormatCurrency(bonificacionEmpleado.ToString) txtSueldoBruto.Text = sueldoBrutoEmpleado.ToString txtIGV.Text = calcularIGV.ToString txtSueldoNeto.Text = calcularSueldoNeto.ToString End Sub Private Sub rbtSoltero_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtSoltero.CheckedChanged opcion = rbtSoltero.Text End Sub Private Sub rbtCasado_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtCasado.CheckedChanged opcion = rbtCasado.Text End Sub Private Sub btnCalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcular.Click CalcularDatosEmpleado() End Sub Private Sub FrmEjercicio_04_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load habilitarEntradas(False) activarOpciones() cboCategoria.SelectedIndex = 0 End Sub Sub configurarDataGridView() dgvEmpleados.RowsDefaultCellStyle.BackColor = Color.LightGreen dgvEmpleados.AlternatingRowsDefaultCellStyle.BackColor = Color.LightYellow End Sub Private Sub dgvEmpleados_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvEmpleados.CellClick cargarDatosEmpleado() End Sub Sub cargarDatosEmpleado() Dim dgvFila As DataGridViewRow = Me.dgvEmpleados.CurrentRow() txtEmpleado.Text = dgvFila.Cells(0).Value cboCategoria.Text = dgvFila.Cells(1).Value nudHijos.Value = dgvFila.Cells(2).Value Dim estCivil As String estCivil = dgvFila.Cells(3).Value

Page 7: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

If estCivil = "Soltero" Then rbtSoltero.Checked = True ElseIf estCivil = "Casado" Then rbtCasado.Checked = True End If Dim nomDsto As String nomDsto = dgvFila.Cells(4).Value If nomDsto = "AFP" Then rbtAfp.Checked = True ElseIf nomDsto = "FNP" Then rbtFnp.Checked = True ElseIf nomDsto = "ES SALUD" Then rbtEsSalud.Checked = True End If txtBono.Text = dgvFila.Cells(6).Value txtSueldoBruto.Text = dgvFila.Cells(7).Value txtIGV.Text = dgvFila.Cells(8).Value txtSueldoNeto.Text = dgvFila.Cells(9).Value End Sub Sub eliminarElementosReporte() If dgvEmpleados.CurrentRow IsNot Nothing Then Me.dgvEmpleados.Rows.Remove(Me.dgvEmpleados.CurrentRow) Else Return End If End Sub Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorrar.Click eliminarElementosReporte() End Sub Sub habilitarEntradas(ByVal estado As Boolean) txtEmpleado.Enabled = estado cboCategoria.Enabled = estado rbtCasado.Enabled = estado rbtSoltero.Enabled = estado rbtAfp.Enabled = estado rbtFnp.Enabled = estado rbtEsSalud.Enabled = estado nudHijos.Enabled = estado btnNuevo.Focus() End Sub Sub activarOpciones() rbtCasado.Checked = False rbtSoltero.Checked = False rbtAfp.Checked = False rbtFnp.Checked = False rbtEsSalud.Checked = False End Sub Sub limpiarEntradas() txtEmpleado.Clear() cboCategoria.SelectedIndex = 0 nudHijos.Value = 0 txtBono.Clear() txtSueldoBruto.Clear() txtIGV.Clear() txtSueldoNeto.Clear() btnNuevo.Focus()

Page 8: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

End Sub Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click habilitarEntradas(True) activarOpciones() limpiarEntradas() End Sub Private Sub rbtAfp_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtAfp.CheckedChanged tipoDsto = rbtAfp.Text End Sub Private Sub rbtFnp_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtFnp.CheckedChanged tipoDsto = rbtFnp.Text End Sub Private Sub rbtEsSalud_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtEsSalud.CheckedChanged tipoDsto = rbtEsSalud.Text End Sub End Class

5. EJERCICIO-05 Permite ingresar la cantidad, nombre del producto, el precio y permita calcular el total, el igv (18%)

y el total a pagar.

Public Class FrmEjercicio_05

Page 9: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Private Sub FrmEjercicio_05_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing 'If MsgBox("¿Desea Salir?", MsgBoxStyle.YesNo, "Sistema") = MsgBoxResult.Yes Then ' End 'Else ' e.Cancel = True 'End If End Sub Private Sub FrmEjercicio_05_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load txtFecha.Text = Now.Date btnNuevoDoc.Focus() cargarProductos() habilitarCliente(False) habilitarProducto(False) activarDocumento(False) End Sub Sub limpiarProducto() cboProducto.SelectedIndex = 0 nudCantidad.Value = 0 txtPrecio.Clear() btnNuevo.Focus() End Sub Sub habilitarProducto(ByVal estado As String) cboProducto.Enabled = estado nudCantidad.Enabled = estado txtPrecio.Enabled = estado btnNuevo.Focus() End Sub Sub habilitarCliente(ByVal estado As String) txtNombres.Enabled = estado txtApellidos.Enabled = estado txtDireccion.Enabled = estado mtbCelular.Enabled = estado mtbTelefono.Enabled = estado txtRUC.Enabled = False btnNuevo.Focus() End Sub Sub limpiarCliente() txtNombres.Clear() txtApellidos.Clear() txtDireccion.Clear() mtbCelular.Clear() mtbTelefono.Clear() txtRUC.Clear() btnNuevo.Focus() End Sub Sub cargarProductos() Dim productos As String() productos = {"<Seleccione>", "Teclado", "Mouse", "Monitor", "Memoria Ram"} cboProducto.Items.AddRange(productos) cboProducto.SelectedIndex = 0 End Sub Function calcularPrecioProducto() As Double Dim preVenta As Double

Page 10: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Dim index As Integer index = cboProducto.SelectedIndex Select Case index Case 1 preVenta = 35 Case 2 preVenta = 23 Case 3 preVenta = 450 Case 4 preVenta = 120 Case Else preVenta = 0 End Select Return preVenta End Function Sub agregarDetalle() Dim detalle As String() Dim importe As Double importe = CDbl(txtPrecio.Text) * CDbl(nudCantidad.Value) detalle = {nudCantidad.Value, txtPrecio.Text, cboProducto.Text, importe.ToString} dgvDetallePedido.Rows.Add(detalle) End Sub Private Sub Realizar_Calculo() '-------------->>>><<<<<------------------------' 'Dim Cantidad As Double Dim IGV, Total, MTotal, MVenta, MIGV As Double 'Dim Precio As Double MTotal = 0 MVenta = 0 MIGV = 0 For n As Integer = 0 To dgvDetallePedido.RowCount - 1 'Cantidad = Val(dgvDetallePedido.Rows(n).Cells(0).Value).ToString 'Precio = Val(dgvDetallePedido.Rows(n).Cells(1).Value) 'Total = (Cantidad * Precio) Total = Val(dgvDetallePedido.Rows(n).Cells(3).Value) 'Me.dgvDetallePedido.Rows(n).Cells(4).Value = Total.ToString("##,##0.00") MTotal += Total Next txtSubTotal.Text = MTotal.ToString("##,##0.00") IGV = (MTotal * 18) / 100 txtIGV.Text = IGV.ToString("##,##0.00") Total = MTotal + IGV txtTotalPagar.Text = Total.ToString("##,##0.00") 'Convertir_Letras() End Sub Private Sub cboProducto_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboProducto.SelectedIndexChanged txtPrecio.Text = calcularPrecioProducto().ToString End Sub Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click agregarDetalle()

Page 11: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Realizar_Calculo() limpiarProducto() End Sub Private Sub btnNuevoDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevoDoc.Click txtDocumento.Text = "0000-001" activarDocumento(True) End Sub Sub activarDocumento(ByVal estado) grbTipoDoc.Enabled = estado End Sub Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click habilitarProducto(True) limpiarProducto() End Sub Private Sub rbtFactura_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtFactura.CheckedChanged habilitarCliente(True) txtRUC.Enabled = True End Sub Private Sub rbtBoleta_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtBoleta.CheckedChanged habilitarCliente(True) txtRUC.Enabled = False End Sub Function reporte() As String Dim sms As String If dgvDetallePedido.Rows.Count > 0 Then sms = "Sr. " & txtNombres.Text & " " & txtApellidos.Text & " Usted debe pagar:" & txtTotalPagar.Text Else sms = "Seleccion sus productos" End If Return MsgBox(sms, MsgBoxStyle.Information, "Cuidado") End Function Private Sub btnReportar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReportar.Click reporte() End Sub Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click If MsgBox("¿Desea Salir?", MsgBoxStyle.YesNo, "Sistema") = MsgBoxResult.Yes Then Close() End If End Sub Private Sub btnCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub End Class

Page 12: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

6. Permite ingresar tu nº de celular y luego escribir tu sms al nº de destino y te mostrara un mensaje

de (“su sms ha sido enviado satisfactoriamente”) ojo solo permite 140 caracteres.

Public Class FrmEjercicio_06 Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click mtbCelular.Text = mtbCelular.Text + "1" End Sub Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click mtbCelular.Text = mtbCelular.Text + "2" End Sub Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click mtbCelular.Text = mtbCelular.Text + "3" End Sub Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click mtbCelular.Text = mtbCelular.Text + "4" End Sub Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click mtbCelular.Text = mtbCelular.Text + "5" End Sub Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click mtbCelular.Text = mtbCelular.Text + "6" End Sub

Page 13: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click mtbCelular.Text = mtbCelular.Text + "7" End Sub Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click mtbCelular.Text = mtbCelular.Text + "8" End Sub Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click mtbCelular.Text = mtbCelular.Text + "9" End Sub Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click mtbCelular.Text = mtbCelular.Text + "0" End Sub Private Sub btnCC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCC.Click mtbCelular.Clear() End Sub Private Sub mtbCelular_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles mtbCelular.MaskInputRejected Dim m As Integer m = Len(mtbCelular.Text) If m = 9 Then txtMensaje.Enabled = True btnEnviar.Enabled = True txtMensaje.Focus() End If End Sub Sub verificarMensaje() Dim n As Integer n = Len(txtMensaje.Text) txtContCar.Text = n If n > 0 Then btnEnviar.Enabled = True btnBorrar.Enabled = True Else btnEnviar.Enabled = False btnBorrar.Enabled = False End If If n >= 140 Then MsgBox("max de caracteres 140, si sigues escribiendo se borran todo") If n = 141 Then txtMensaje.Text = "" End If End If End Sub Private Sub txtMensaje_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMensaje.TextChanged verificarMensaje() End Sub

Page 14: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Private Sub btnEnviar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnviar.Click MsgBox("su mensaje ha sido enviado satisfactoriamente") mtbCelular.Text = "" txtMensaje.Text = "" txtContCar.Text = "" End Sub Private Sub FrmEjercicio_06_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load txtMaxCar.Enabled = False txtMaxCar.Text = 140 End Sub Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorrar.Click txtMensaje.Clear() End Sub Private Sub btnBorrarUno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorrarUno.Click If Len(mtbCelular.Text) > 0 Then mtbCelular.Text = Mid(mtbCelular.Text, 1, Len(mtbCelular.Text) - 1) Else MsgBox("Ingrese número de celular") End If End Sub End Class

7. Permite calcular el afp, fonavi y es salud tanto, si es de los siguiente descuentos (“nombrado,

contratado y practicante”); según estas características que tenemos: movilidad, total ingreso, total

descuento, sueldo a pagar.

Page 15: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Public Class FrmEjercicio_07 Public dscto As Double Private Sub FrmEjercicio_07_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load activar(False, False, False) End Sub Function condicionLaboral() As Double Dim sueldoBasico As Double If rbtNombrado.Checked = True Then sueldoBasico = 1200 ElseIf rbtContratado.Checked Then sueldoBasico = 800 ElseIf rbtPracticante.Checked = True Then sueldoBasico = 600 End If Return sueldoBasico End Function Sub descuentos() Dim dscto As Double If chkAFP.Checked = True Then dscto = 0.1 * CDbl(txtSueldo.Text) txtAfp.Text = dscto ElseIf chkFONAVI.Checked = True Then dscto = 0.05 * CDbl(txtSueldo.Text) txtFonavi.Text = dscto ElseIf chkESSALUD.Checked = True Then dscto = 0.08 * CDbl(txtSueldo.Text) txtEsSalud.Text = dscto ElseIf chkFNP.Checked = True Then dscto = 0.06 * CDbl(txtSueldo.Text) txtFnp.Text = dscto ElseIf chkIMP4.Checked = True Then dscto = 0.05 * CDbl(txtSueldo.Text) txtImp4.Text = dscto End If End Sub Private Sub rbtNombrado_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtNombrado.CheckedChanged txtSueldo.Text = condicionLaboral() activar(True, True, True) End Sub Private Sub rbtContratado_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtContratado.CheckedChanged txtSueldo.Text = condicionLaboral() activar(True, True, True) End Sub Private Sub rbtPracticante_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtPracticante.CheckedChanged txtSueldo.Text = condicionLaboral() activar(True, True, True) End Sub Private Sub chkAFP_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkAFP.CheckedChanged 'descuentos()

Page 16: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

If chkAFP.Checked = True Then dscto = 0.1 * CDbl(txtSueldo.Text) txtAfp.Text = dscto Else txtAfp.Text = 0 End If End Sub Private Sub chkFONAVI_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFONAVI.CheckedChanged 'descuentos() If chkFONAVI.Checked = True Then dscto = 0.05 * CDbl(txtSueldo.Text) txtFonavi.Text = dscto Else txtFonavi.Text = 0 End If End Sub Private Sub chkESSALUD_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkESSALUD.CheckedChanged ' descuentos() If chkESSALUD.Checked = True Then dscto = 0.08 * CDbl(txtSueldo.Text) txtEsSalud.Text = dscto Else txtEsSalud.Text = 0 End If End Sub Private Sub chkFNP_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFNP.CheckedChanged ' descuentos() If chkFNP.Checked = True Then dscto = 0.06 * CDbl(txtSueldo.Text) txtFnp.Text = dscto Else txtFnp.Text = 0 End If End Sub Private Sub chkIMP4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkIMP4.CheckedChanged 'descuentos() If chkIMP4.Checked = True Then dscto = 0.05 * CDbl(txtSueldo.Text) txtImp4.Text = dscto Else txtImp4.Text = 0 End If End Sub Sub activar(ByVal estado1 As Boolean, ByVal estado2 As Boolean, ByVal estado3 As Boolean) grbConLaboral.Enabled = estado1

Page 17: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

grbDatosEmpl.Enabled = estado2 grbDsctos.Enabled = estado3 End Sub Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click activar(True, False, False) End Sub Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click If MsgBox("¿Desea Salir?", MsgBoxStyle.YesNo, "Sistema") = MsgBoxResult.Yes Then Close() End If End Sub Sub reporte() txtMovilidad.Text = 200 txtTotIngreso.Text = CDbl(txtSueldo.Text) + CDbl(txtMovilidad.Text) txtTotDscto.Text = CDbl(txtAfp.Text) + CDbl(txtFonavi.Text) + CDbl(txtFnp.Text) + CDbl(txtEsSalud.Text) + CDbl(txtImp4.Text) txtSueldoPagar.Text = CDbl(txtTotIngreso.Text) + CDbl(txtTotDscto.Text) End Sub Private Sub btnCalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcular.Click reporte() End Sub End Class

8. Permite el ingreso del nombre y apellido y seleccionar el nivel del combo, y permite agregar al

listbox. Según tu nivel (“a”, “b”, “c”). La cantidad de socios empieza a contar es decir eso se da en la

categoría de la estadística de socios y tiene las opciones (“nuevo, agregar, eliminar, editar, eliminar

todo).

Public Class FrmEjercicio_08

Page 18: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Dim cantNA, cantNB, cantNC, posicion As Integer Dim accion As Integer = 0 Private Sub FrmEjercicio_08_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load habilitar(False) verificar() End Sub Sub AgregarDatos() If txtSocio.Text <> "" Then lsbSocios.Items.Add(txtSocio.Text) lsbNivel.Items.Add(cboNivel.Text) Else MsgBox("Ingrese Los Datos") End If End Sub Sub verificar() If Len(txtSocio.Text) = 0 Then cboNivel.Enabled = False Else cboNivel.Enabled = True End If End Sub Sub cantidadSociosnivel() Dim i As Integer For i = 0 To lsbNivel.Items.Count - 1 If lsbNivel.Items(i) = "A" Then cantNA = cantNA + 1 ElseIf lsbNivel.Items(i) = "B" Then cantNB = cantNB + 1 ElseIf lsbNivel.Items(i) = "C" Then cantNC = cantNC + 1 End If Next i End Sub Sub reporteDatos() txtCantA.Text = cantNA txtCantB.Text = cantNB txtCantC.Text = cantNC End Sub Sub limpiar() txtSocio.Clear() cboNivel.SelectedIndex = 0 cantNA = 0 : cantNB = 0 : cantNC = 0 btnNuevo.Focus() End Sub Sub habilitar(ByVal estado As Boolean) txtSocio.Enabled = estado End Sub Private Sub txtSocio_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSocio.TextChanged verificar() End Sub Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click habilitar(True)

Page 19: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

limpiar() accion = 1 End Sub Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click If accion = 1 Then AgregarDatos() limpiar() habilitar(False) lsbNivel.Refresh() lsbSocios.Refresh() ElseIf accion = 2 Then actualizarDatos() limpiar() habilitar(False) lsbNivel.Refresh() lsbSocios.Refresh() End If End Sub Sub EliminarDatos() If lsbSocios.Items.Count > 0 Then Dim indice As Integer indice = lsbSocios.SelectedIndex lsbSocios.Items.RemoveAt(indice) lsbNivel.Items.RemoveAt(indice) Else MsgBox("La lista está vacia") End If End Sub Sub limpiarListas() lsbSocios.Items.Clear() lsbNivel.Items.Clear() End Sub Private Sub btnEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEliminar.Click EliminarDatos() End Sub Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click limpiarListas() End Sub Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click If MsgBox("¿Desea Salir?", MsgBoxStyle.YesNo, "Sistema") = MsgBoxResult.Yes Then Close() End If End Sub Sub actualizarDatos() 'lsbSocios.Items.RemoveAt(posicion) lsbSocios.Items(posicion) = txtSocio.Text lsbNivel.Items(posicion) = cboNivel.Text lsbSocios.Refresh() lsbNivel.Refresh()

Page 20: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

End Sub Private Sub btnReportar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReportar.Click cantidadSociosnivel() reporteDatos() End Sub Private Sub lsbSocios_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lsbSocios.SelectedIndexChanged posicion = lsbSocios.SelectedIndex txtSocio.Text = lsbSocios.SelectedItem cboNivel.Text = lsbNivel.Items(posicion) accion = 2 End Sub Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click If lsbSocios.Items.Count > 0 Then habilitar(True) accion = 2 Else MsgBox("La lista está vacia") End If End Sub End Class

9. EJERCICIO 09: PROFORMA VENTA DE COMPUTADORAS

Page 21: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

Page 22: Practica 1 Taller de Programacion Vb Net

Ing. Hobby Saavedra Rosas Visual Basic .Net

10. EJERCICIO 10: