UNIVERSIDAD NACIONAL DE INGENIERIA DEPARTAMENTO DE LENGUAJES Y SIMULACION FEC-UNI Facilitador: Ing. Adil G. Lpez
Realizar las siguientes declaraciones Globales Dim N As Integer Dim Max = 2 Dim Nota(Max - 1) As Integer Dim Nombre(Max - 1) As String Dim i As Integer, band As Boolean, nom As String, k As Integer
Dar doble click en el formulario para programar el evento Form Load cbOpciones.Items.Add("Buscar") cbOpciones.Items.Add("Actualizar") cbOpciones.Items.Add("Eliminar") cbOpciones.Items.Add("Imprimir Todos") txtNom.ReadOnly = True txtNot.ReadOnly = True cbOpciones.DropDownStyle = ComboBoxStyle.DropDownList
En el Evento Click del botn Ingresar()
Usaremos el evento Keypress del textbox de Nota Private Sub txtNota_KeyPress() If Asc(e.KeyChar) = 13 Then Ingresar() End If End Sub
Para programar este evento dar doble click en el combobox
Dim valor As Integer valor = cbOpciones.SelectedIndex Select Case valor Case 0 Buscar() Case 1 Actualizar() Case 2 Eliminar() Case 3 Imprimir() End Select
Escribir las siguientes subrutinas
UNIVERSIDAD NACIONAL DE INGENIERIA DEPARTAMENTO DE LENGUAJES Y SIMULACION FEC-UNI Facilitador: Ing. Adil G. Lpez
Private Sub Ingresar() If N < Max Then Nombre(N) = txtNombre.Text Nota(N) = CInt(txtNota.Text) N = N + 1 MsgBox("Estudiante Ingresado") Limpiar() Else MsgBox("El elemento no puede insertarse") Limpiar() End If End Sub
Private Sub Buscar() i = 1 nom = InputBox("Introduzca el estudiantes a buscar") While (i < N And nom <> Nombre(i)) i = i + 1 End While If i > N Then MsgBox("No hay estudiantes con ese nombre") Else txtNom.Text = Nombre(i) txtNot.Text = Nota(i) End If End Sub
Private Sub Eliminar() If N > 0 Then i = 0 band = False nom = InputBox("De el nombre del estudiante a eliminar") While (i < N And band = False) If Nombre(i) = nom Then band = True N = N - 1 For k = i To N - 1 Nombre(k) = Nombre(k + 1) Nota(k) = Nota(k + 1) Next Else i = i + 1 End If End While If band = False Then MsgBox(nom & " no se encuentra") End If Else MsgBox("No hay datos almacenados") End If End Sub
UNIVERSIDAD NACIONAL DE INGENIERIA DEPARTAMENTO DE LENGUAJES Y SIMULACION FEC-UNI Facilitador: Ing. Adil G. Lpez
Private Sub Actualizar() If N > 0 Then i = 0 band = False nom = InputBox("Introduzca el nombre a modificar nota") While (i < N And band = False) If Nombre(i) = nom Then Nota(i) = CInt(InputBox("Introduzca nueva nota")) band = True Else i = i + 1 End If End While If band = False Then MsgBox(nom & " no se encuentra") End If Else MsgBox("No hay datos almacenados")
End If End Sub
Private Sub Imprimir() lbImprimir.Items.Clear() If N > 0 Then For i = 0 To N - 1 lbImprimir.Items.Add(Nombre(i) & vbTab & Nota(i)) Next Else MsgBox("No hay datos") End If End Sub
Sub Limpiar() txtNombre.Clear() txtNota.Clear() txtNombre.Focus() End Sub