Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
Ejercicio 1
Dim saludo As String * 10 Private Sub Command1_Click() Dim Nombre As String * 10 Nombre = "Joaquim" saludo = "HOLA" Print saludo; y; Nombre End Sub Private Sub Command2_Click() saludo = "ADIOS" Print saludo End Sub Ejercicio 2
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
Private Sub Boton_dividir_Click() Dim result As Integer result = Val(Numero_uno.Text) / Val(Numero_dos.Text) Numero_resultado.Text = Str(result) End Sub Private Sub Boton_multiplicar_Click() Dim result As Integer result = Val(Numero_uno.Text) * Val(Numero_dos.Text) Numero_resultado.Text = Str(result) End Sub Private Sub Boton_restar_Click() Dim result As Integer result = Val(Numero_uno.Text) - Val(Numero_dos.Text) Numero_resultado.Text = Str(result) End Sub Private Sub Boton_salir_Click() End End Sub Private Sub Boton_Sumar_Click() Dim result As Integer result = Val(Numero_uno.Text) + Val(Numero_dos.Text) Numero_resultado.Text = Str(result) End Sub Ejercicio 3
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
Private Sub Command1_Click() Dim result, resulta As Double result = Val([Link]) * (60) [Link] = Str(result) resulta = Val([Link]) * (60) [Link] = Str(resulta) End Sub Private Sub Command2_Click() End End Sub Ejercicio 4
Private Sub Azul_Click() [Link] = &HFF0000 End Sub Private Sub Command1_Click() End End Sub Private Sub Cursiva_Click() [Link] = True [Link] = False End Sub Private Sub Form_Load() [Link] = True [Link] = True [Link] = False [Link] = False [Link] = &HFF0000 End Sub 3
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
Private Sub Negrilla_Click() [Link] = True [Link] = False End Sub Private Sub Normal_Click() [Link] = False [Link] = False End Sub Private Sub Verde_Click() [Link] = &HFF00& End Sub Ejercicio 5
Private Sub Ape_GotFocus() [Link] = 0 [Link] = Len([Link]) End Sub Private Sub Boton_aadir_Click() totalregistros = totalregistros + 1 If totalregistros > 50 Then MsgBox "losta completa", 16, "error" Else agenda(totalregistros).Nombre = [Link] agenda(totalregistros).apellidos = [Link] agenda(totalregistros).telefono = [Link] agenda(totalregistros).Edad = Val([Link]) Lista_1.AddItem [Link] Lista_2.AddItem [Link] End If [Link] End Sub 4
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
Private Sub Boton_eliminar_Click(Index As Integer) Dim I, B As Integer For I = 1 To totalregistros If (RTrim$(Lista_1.Text) = RTrim$(agenda(I).Nombre)) Then Exit For End If Next I [Link] = agenda(I).Nombre [Link] = agenda(I).apellidos [Link] = agenda(I).telefono [Link] = Str(agenda(I).Edad) B = MsgBox("Eliminar Registro:" + [Link], 3 + 32, "Eliminar") If B = 6 Then Lista_1.RemoveItem I - 1 totalregistros = totalregistros - 1 For j = I To totalregistros agenda(j).Nombre = agenda(j + 1).Nombre agenda(j).apellidos = agenda(j + 1).apellidos agenda(j).telefono = agenda(j + 1).telefono agenda(j).Edad = agenda(j + 1).Edad Next j [Link] = "" [Link] = "" [Link] = "" [Link] = "" End If End Sub Private Sub Boton_fin_Click(Index As Integer) End End Sub Private Sub Eda_GotFocus() [Link] = 0 [Link] = Len([Link]) End Sub Private Sub Form_Load() totalregistros = 0 End Sub Private Sub Lista_2_Change() Dim n As Integer n = Lista_2.ListIndex + 1 [Link] = agenda(n).Nombre [Link] = agenda(n).apellidos [Link] = agenda(n).telefono [Link] = agenda(n).Edad End Sub 5
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
Private Sub Nom_GotFocus() [Link] = 0 [Link] = Len([Link]) End Sub Private Sub Tel_GotFocus() [Link] = 0 [Link] = Len([Link]) End Sub Crear un mdulo Type registro Nombre As String * 15 apellidos As String * 25 telefono As String * 15 Edad As String * 3 End Type Global agenda(1 To 50) As registro Global totalregistros As Integer Ejercicio 6
Private Sub Boton_fin_Click() End End Sub Private Sub cd_Click() Dim precio As Long Dim res As Long precio = 0 res = 0 If [Link] = 1 Then precio = Val([Link]) + 20000 Else precio = Val([Link]) = -20000 End If 6
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
[Link] = precio res = Val([Link]) + Val([Link]) [Link] = res End Sub Private Sub Form_Load() [Link] = 1 [Link] = 1 [Link] = 1 [Link] = "0" End Sub Private Sub kit_Click() Dim precio As Long Dim res As Long precio = 0 res = 0 If [Link] = 1 Then precio = Val([Link]) + 35000 Else precio = Val([Link]) = -35000 End If [Link] = precio res = Val([Link]) + Val([Link]) [Link] = res End Sub Private Sub pantalla_Click() Dim precio As Long Dim res As Long precio = 0 res = 0 If [Link] = 1 Then precio = Val([Link]) + 120000 Else precio = Val([Link]) = -120000 End If [Link] = precio res = Val([Link]) + Val([Link]) [Link] = res End Sub Private Sub Ram_Click() Dim precio As Long Dim res As Long precio = 0 res = 0 If [Link] = 1 Then precio = Val([Link]) + 80000 7
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
Else precio = Val([Link]) = -80000 End If [Link] = precio res = Val([Link]) + Val([Link]) [Link] = res End Sub Ejercicio 7
Private Sub icono_1_Click() [Link] = LoadPicture("C:\Archivos de programa\Microsoft Visual Studio\Common\Graphics\Metafile\Business\[Link]") End Sub Private Sub icono_2_Click() [Link] = LoadPicture("C:\Archivos de programa\Microsoft Visual Studio\Common\Graphics\Metafile\Business\[Link]") End Sub Private Sub icono_3_Click() [Link] = LoadPicture("C:\Archivos de programa\Microsoft Visual Studio\Common\Graphics\Metafile\Business\[Link]") End Sub Ejercicio 8 Dim n As Integer Private Sub btnBorrar_Click() If n = 0 Then MsgBox "Minimo 1 linea", 16, "Error" Exit Sub End If 8
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
Unload txtRef(n) Unload txtDes(n) Unload txtCan(n) Unload txtPre(n) n=n-1 End Sub
Private Sub btnFin_Click() Unload Me End Sub Private Sub btnImprimir_Click() Dim i As Integer [Link] = "Arial" [Link] = "10" For i = 0 To [Link] - 1 If TypeOf Controls(i) Is TextBox Then GoSub posicin [Link] .Underline = False [Link] Controls(i).Text End If If TypeOf Controls(i) Is Label Then GoSub posicin [Link] .Underline = True [Link] Controls(i).Caption End If Next i [Link] Exit Sub posicin: [Link] = Controls(i).Left 9
Ejercicios de Visual Basic
Prof.: Lic. Toledo Marcelo Alejandro e-mail: mtoledo@[Link]
[Link] = Controls(i).Top Return End Sub Private Sub btnNueva_Click() n=1 If n > 4 Then MsgBox "Albarn completo", 16, "Error" n=4 Exit Sub End If 'Referencia Load txtRef(n) txtRef(n).Top = txtRef(n - 1).Top + 350 txtRef(n).Visible = True txtRef(n).Text = "" 'Descripcin Load txtDes(n) txtDes(n).Top = txtDes(n - 1).Top + 350 txtDes(n).Visible = True txtDes(n).Text = "" 'Precio Load txtPre(n) txtPre(n).Top = txtPre(n - 1).Top + 350 txtPre(n).Visible = True txtPre(n).Text = "" 'Cantidad Load txtCan(n) txtCan(n).Top = txtCan(n - 1).Top + 350 txtCan(n).Visible = True txtCan(n).Text = "" End Sub Private Sub Form_Load() n=0 End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim Msg Msg = "Desea salir de la aplicacin?" If MsgBox(Msg, 36, [Link]) = 7 Then Cancel = True End If End Sub
10