SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 1
EVENTOS PARA REALIZAR ACCESO DE ENTRADA
Private Sub cmdAceptar_Click()
If (TxtUsuario.Text = "1234") Then
Form2.Show
Unload Me
MsgBox ("Bienvenido a Kazak Multimedia Player"), vbInformation, "Mensaje"
Else
MsgBox ("Por favor inserte la contraseña correcta"), vbCritical, "¡Error!"
TxtUsuario = ""
TxtUsuario.SetFocus
End If
End Sub
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 2
CALCULADORA
Public Suma As Double
Private Sub Command1_Click()
Dim Valor As Double
If Text1.Text = "" Then
Valor = 0
Else
Valor = CDbl(Text1.Text)
End If
Suma = Suma + Valor
LblResultado.Caption = Suma
Text1.Text = ""
End Sub
Private Sub mnumerica_Click()
L.Show
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 3
End Sub
Private Sub OptDividir_Click()
If Val(TxtSegundoValor.Text) = 0 Then
MsgBox ("No se puede dividir por cero.")
Else
TxtResultado.Text = Val(TxtPrimerValor.Text) / Val(TxtSegundoValor.Text)
End If
End Sub
Private Sub OptMultiplicar_Click()
TxtResultado.Text = Val(TxtPrimerValor.Text) * Val(TxtSegundoValor.Text)
End Sub
Private Sub OptRestar_Click()
TxtResultado.Text = Val(TxtPrimerValor.Text) - Val(TxtSegundoValor.Text)
End Sub
Private Sub OptSumar_Click()
TxtResultado.Text = Val(TxtPrimerValor.Text) + Val(TxtSegundoValor.Text)
End Sub
Private Sub TxtPrimerValor_KeyPress(KeyAscii As Integer)
If InStr("0123456789" & Chr(8) & Chr(13), Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 4
Private Sub TxtSegundoValor_KeyPress(KeyAscii As Integer)
If InStr("0123456789" & Chr(8) & Chr(13), Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
PARA HACER UN REGISTRO
Private Sub Command1_Click()
Dim Clave As String
Clave = "1234512345123451234512345"
'Verifica que la contraseña es igual a la que contiene las cajas.
If TxtCaja1.Text & TxtCaja2.Text & TxtCaja3.Text & TxtCaja4.Text & TxtCaja5.Text = Clave Then
MsgBox ("Contraseña Correcta.")
Unload Me ' Cierra esta ventana.
Else
MsgBox ("Contraseña Incorrecta."), vbCritical, "Registro"
TxtCaja1.SetFocus ' Hace que la primera caja reciba el enfoque.
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 5
Private Sub TxtCaja1_Change()
'Verificamos que Si la primera caja de texto tiene cinco caracteres.
If Len(TxtCaja1.Text) = 5 Then
TxtCaja2.SetFocus ' Saltamos a la segunda caja.
End If
End Sub
Private Sub TxtCaja2_Change()
'Verificamos que Si la primera caja de texto tiene cinco caracteres.
If Len(TxtCaja2.Text) = 5 Then
TxtCaja3.SetFocus ' Saltamos a la tercera caja.
End If
End Sub
Private Sub TxtCaja3_Change()
'Verificamos que Si la primera caja de texto tiene cinco caracteres.
If Len(TxtCaja3.Text) = 5 Then
TxtCaja4.SetFocus ' Saltamos a la cuarta caja.
End If
End Sub
Private Sub TxtCaja4_Change()
'Verificamos que Si la primera caja de texto tiene cinco caracteres.
If Len(TxtCaja4.Text) = 5 Then
TxtCaja5.SetFocus ' Saltamos a la quinta caja.
End If
End Sub
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 6
Private Sub TxtCaja5_Change()
'Verificamos que Si la cuarta caja de texto tiene cinco caracteres.
'If Len(TxtCaja5.Text) = 5 Then
'cmdRegistrar.SetFocus
'Hacemos que el botón Registrar reciba el enfoque.
'End If
End Sub
CAMBIO DE COLORES EN LOS LABELS
Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal
lpszSoundName As String, ByVal uFlags As Long) As Long
Dim MoveCursor As Boolean
Private Sub Command1_Click()
End Sub
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 7
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Desactiva el color de fondo de las opciones
'If Label3.BackStyle = 1 Then Label3.BackStyle = 0
'If Label4.BackStyle = 1 Then Label4.BackStyle = 0
'If Label5.BackStyle = 1 Then Label5.BackStyle = 0
'If Label6.BackStyle = 1 Then Label6.BackStyle = 0
'If Label7.BackStyle = 1 Then Label7.BackStyle = 0
MoveCursor = True
End Sub
Private Sub Label3_Click()
FrmInscripcion.Show
End Sub
Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Label3.BackStyle = 0 Then
Label3.BackStyle = 1 ' Permite que se establezca el color de fondo
Label3.BackColor = &H8000& ' Pone el color verde
'Desactiva el color de fondo de las demás opciones
Label4.BackStyle = 0
Label5.BackStyle = 0
Label6.BackStyle = 0
Label7.BackStyle = 0
End If
End Sub
Private Sub Label4_Click()
FrmTexto.Show
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 8
End Sub
Private Sub Label4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Label4.BackStyle = 0 Then
Label4.BackStyle = 1 ' Permite que se establezca el color de fondo
Label4.BackColor = &H8000& ' Pone el color verde
'Desactiva el color de fondo de las demás opciones
Label3.BackStyle = 0
Label5.BackStyle = 0
Label6.BackStyle = 0
Label7.BackStyle = 0
End If
End Sub
Private Sub Label5_Click()
FrmRegistro.Show
End Sub
Private Sub Label5_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Label5.BackStyle = 0 Then
Label5.BackStyle = 1 ' Permite que se establezca el color de fondo
Label5.BackColor = &H8000& ' Pone el color verde
'Desactiva el color de fondo de las demás opciones
Label3.BackStyle = 0
Label4.BackStyle = 0
Label6.BackStyle = 0
Label7.BackStyle = 0
End If
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 9
End Sub
Private Sub Label6_Click()
FrmBoton.Show
End Sub
Private Sub Label6_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Label6.BackStyle = 0 Then
Label6.BackStyle = 1 ' Permite que se establezca el color de fondo
Label6.BackColor = &H8000& ' Pone el color verde
'Desactiva el color de fondo de las demás opciones
Label3.BackStyle = 0
Label4.BackStyle = 0
Label5.BackStyle = 0
Label7.BackStyle = 0
End If
End Sub
Private Sub Label7_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Label7.BackStyle = 0 Then
Label7.BackStyle = 1 ' Permite que se establezca el color de fondo
Label7.BackColor = &H8000& ' Pone el color verde
'Desactiva el color de fondo de las demás opciones
Label3.BackStyle = 0
Label4.BackStyle = 0
Label5.BackStyle = 0
Label6.BackStyle = 0
End If
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 10
End Sub
'en las etiquetas seleccionadas hemos seleccionado en las
'propiedades Autosize=true y en BackStyle= 0 – Transparent
INSCRIPCIONES SOLO PARA MAYORES DE EDAD
Private Sub Command1_Click()
'Verifica si la caja de texto Nombre esta vacía.
If Len(Trim(TxtNombre.Text)) = 0 Then
MsgBox ("Debe introducir el Nombre.")
TxtNombre.SetFocus ' Hace que la caja reciba el enfoque.
'Verifica si la caja de texto Apellido esta vacía.
ElseIf Len(Trim(TxtApellido.Text)) = 0 Then
MsgBox ("Debe introducir el Apellido.")
TxtApellido.SetFocus ' Hace que la caja reciba el enfoque.
'Verifica si la caja de texto Cédula esta vacía.
ElseIf Len(Trim(TxtCedula.Text)) = 0 Then
MsgBox ("Debe introducir la Cedula.")
TxtCedula.SetFocus ' Hace que la caja reciba el enfoque.
'Verifica si la caja de texto Edad esta vacía.
ElseIf Len(Trim(TxtEdad.Text)) = 0 Then
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 11
MsgBox ("Debe introducir la Edad.")
TxtEdad.SetFocus
'Verifica si la persona es menor de Edad.
ElseIf Val(TxtEdad.Text) < 18 Then
'MsgBox(“No se registran personas menores de edad.”)
TxtEdad.SetFocus
'Verifica si la caja de texto Dirección esta vacía.
ElseIf Len(Trim(TxtDireccion.Text)) = 0 Then
MsgBox ("Debe introducir la Dirección.")
TxtDireccion.SetFocus ' Hace que la caja reciba el enfoque.
Else
'Aquí se escribe la codificación para almacenar los datos en la Base de datos.
'En nuestro caso mostraremos un mensaje para hacer un simulacro.
MsgBox ("El registro ha sido almacenado satisfactoriamente.")
'Limpiamos las cajas.
TxtNombre.Text = ""
TxtApellido.Text = ""
TxtCedula.Text = ""
TxtEdad.Text = ""
TxtTelefono.Text = ""
TxtDireccion.Text = ""
End If
End Sub
Private Sub Command2_Click()
Dim respuesta
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 12
respuesta = MsgBox("¿Desea salir de la aplicación?", vbCritical _
+ vbYesNo, "Cerrar")
If respuesta = vbYes Then
Unload Me
End If
End Sub
Private Sub CmdRegistrar_Click()
End Sub
Private Sub Command3_Click()
CommonDialog1.Filter = "Video (*.mpeg) *.mpeg|Musica (*.mp3) *.mp3|Todos los
archivos (*.*) *.*|"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowOpen
LbNom.Caption = CommonDialog1.FileTitle
MediaPlayer1.FileName = LbNom
End Sub
Private Sub TxtApellido_Validate(Cancel As Boolean)
'Verifica si la caja de texto esta vacía.
If Len(Trim(TxtApellido.Text)) = 0 Then
MsgBox ("Debe introducir el Apellido."), vbCritical
Cancel = True ' Hace que el enfoque NO pase a otro control.
End If
End Sub
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 13
Private Sub TxtCedula_Validate(Cancel As Boolean)
'Verifica si la caja de texto esta vacía.
If Len(Trim(TxtCedula.Text)) = 0 Then
MsgBox ("Debe introducir la Cédula."), vbCritical
Cancel = True ' Hace que el enfoque NO pase a otro control.
End If
TxtCedula.SetFocus
End Sub
Private Sub TxtDireccion_Validate(Cancel As Boolean)
'Verifica si la caja de texto esta vacía.
If Len(Trim(TxtDireccion.Text)) = 0 Then
MsgBox ("Debe introducir la Dirección."), vbCritical
Cancel = True ' Hace que el enfoque NO pase a otro control.
End If
End Sub
Private Sub TxtEdad_Validate(Cancel As Boolean)
'Verifica si la caja de texto esta vacía.
If Len(Trim(TxtEdad.Text)) = 0 Then
MsgBox ("Debe introducir la Edad."), vbCritical
Cancel = True ' Hace que el enfoque NO pase a otro control.
'Verifica que la edad cumpla con el criterio establecido.
ElseIf Val(TxtEdad.Text) < 18 Then
MsgBox ("No se registran menores de edad."), vbCritical, "Mensaje"
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 14
Cancel = True ' Hace que el enfoque NO pase a otro control.
End If
End Sub
Private Sub TxtNombre_Validate(Cancel As Boolean)
'Verifica si la caja de texto esta vacía.
If Len(Trim(TxtNombre.Text)) = 0 Then
MsgBox ("Debe introducir el Nombre."), vbCritical, "Mensaje"
Cancel = True ' Hace que el enfoque NO pase a otro control.
End If
End Sub
IMPRIMIR EL FORMULARIO
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 15
Private Sub Command1_Click()
Printer.Orientation = 1
' La orientación del papel es vertical
Printer.FontSize = 12
'Tamaño de la letra
Printer.Print
'Un renglón en blanco o salto de carro
Printer.Print
Printer.Print
Printer.Print Tab(15); Label1.Caption; Tab(30); Text1.Text
'Aquí damos la orden de impresión del caption de la label1 a 15 espacios
'del margen izquerdo y luego a 30 espacios del margen izquierdo el
'contenido del texto.
Printer.Print
Printer.Print
Printer.Print Tab(15); Label2.Caption; Tab(30); Text2.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label3.Caption; Tab(30); Text3.Text
Printer.Print
Printer.Print
Printer.Print
Printer.Print Tab(15); Label4.Caption; Tab(30); Text4.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label5.Caption; Tab(30); Text5.Text
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 16
Printer.Print
Printer.Print
Printer.Print Tab(15); Label6.Caption; Tab(30); Text6.Text
Printer.EndDoc
'damos por terminada la impresión
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Command3_Click()
Form3.Show
End Sub
COBRO DE SERVICIOS DE COMIDA
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 17
Dim Sandwich As Single
Dim Gaseosa As Single
Dim Refresco As Single
Dim PapasFritas As Single
'Declaración de variables para la cantidad de cada una.
Dim CantidadHamburguesa As Integer
Dim CantidadHotDog As Integer
Dim CantidadSandwich As Integer
Dim CantidadGaseosa As Integer
Dim CantidadRefresco As Integer
Dim CantidadPapasFritas As Integer
Private Sub cmdCalcular_Click()
'Multiplicando la cantidad por el precio y sumando para hallar el total.
Total = (CantidadHamburguesa * Hamburguesa) + (CantidadHotDog * HotDog) + _
(CantidadSandwich * Sandwich) + (CantidadGaseosa * Gaseosa) + _
(CantidadRefresco * Refresco) + (CantidadPapasFritas * PapasFritas)
LblTotal.Caption = "$ " & Total
End Sub
Private Sub cmdSalir_Click()
End
End Sub
Private Sub Form_Load()
'Inicializar las variables
'Precio de los productos
Hamburguesa = 20.5
HotDog = 19.25
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 18
Sandwich = 17.5
PapasFritas = 4.5
Refresco = 4
Gaseosa = 5
End Sub
Private Sub optOtroPedido_Click()
'Limpiar el label lblTotal.
LblTotal.Caption = ""
'Inicializar las variables.
CantidadHamburguesa = 0
CantidadGaseosa = 0
CantidadPapasFritas = 0
CantidadHotDog = 0
CantidadSandwich = 0
CantidadRefresco = 0
'Habilitar todas las cajas de texto para poder entrar datos en todas.
TxtHamburguesa.Enabled = True
TxtHotDog.Enabled = True
TxtSandwich.Enabled = True
TxtGaseosa.Enabled = True
TxtRefresco.Enabled = True
TxtPapasFritas.Enabled = True
'Limpiar todas las cajas de texto.
TxtHamburguesa.Text = ""
TxtHotDog.Text = ""
TxtSandwich.Text = ""
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 19
TxtGaseosa.Text = ""
TxtRefresco.Text = ""
TxtPapasFritas.Text = ""
End Sub
Private Sub optPedido1_Click()
'Hamburguesas,Gaseosa y Papas Fritas.
'Limpiar el label lblTotal.
LblTotal.Caption = ""
If OptPedido1.Value Then 'si esta chequeado.
'Inicializar las variables.
CantidadHamburguesa = 1
CantidadGaseosa = 1
CantidadPapasFritas = 1
CantidadHotDog = 0
CantidadSandwich = 0
CantidadRefresco = 0
'Inicializar la caja de texto.
TxtHamburguesa.Text = CantidadHamburguesa
TxtGaseosa.Text = CantidadGaseosa
TxtPapasFritas.Text = CantidadPapasFritas
'Habilitar las cajas de texto.
TxtHamburguesa.Enabled = True
TxtGaseosa.Enabled = True
TxtPapasFritas.Enabled = True
'Deshabilitar las otras cajas de texto.
TxtHotDog.Enabled = False
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 20
TxtSandwich.Enabled = False
TxtRefresco.Enabled = False
'Limpiar las otras cajas de texto.
TxtHotDog.Text = ""
TxtSandwich.Text = ""
TxtRefresco.Text = ""
End If
End Sub
Private Sub optPedido2_Click()
'HotDog,Gaseosa y Papas Fritas.
'Limpiar el label lblTotal.
LblTotal.Caption = ""
If OptPedido2.Value Then
'Inicializar las variables.
CantidadHotDog = 1
CantidadGaseosa = 1
CantidadPapasFritas = 1
CantidadHamburguesa = 0
CantidadSandwich = 0
CantidadRefresco = 0
'Inicializar la caja de texto.
TxtHotDog.Text = CantidadHotDog
TxtGaseosa.Text = CantidadGaseosa
TxtPapasFritas.Text = CantidadPapasFritas
'Habilitar las cajas de texto.
TxtHotDog.Enabled = True
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 21
TxtGaseosa.Enabled = True
TxtPapasFritas.Enabled = True
'Deshabilitar las otras cajas de texto.
TxtHamburguesa.Enabled = False
TxtSandwich.Text = False
TxtRefresco.Text = False
'Limpiar las otras cajas de texto.
TxtHamburguesa.Text = ""
TxtSandwich.Text = ""
TxtRefresco.Text = ""
End If
End Sub
Private Sub optPedido3_Click()
'Sanwich,Gaseosa y Papas Fritas.
'Limpiar el label lblTotal
LblTotal.Caption = ""
If OptPedido3.Value Then
'Inicializar las variables
CantidadSandwich = 1
CantidadGaseosa = 1
CantidadPapasFritas = 1
CantidadHamburguesa = 0
CantidadHotDog = 0
CantidadRefresco = 0
'Inicializar la caja de texto
TxtSandwich.Text = CantidadSandwich
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 22
TxtGaseosa.Text = CantidadGaseosa
TxtPapasFritas.Text = CantidadPapasFritas
'Habilitar las cajas de texto
TxtSandwich.Enabled = True
TxtGaseosa.Enabled = True
TxtPapasFritas.Enabled = True
'Deshabilitar las otras cajas de texto.
TxtHotDog.Enabled = False
TxtHamburguesa.Enabled = False
TxtRefresco.Enabled = False
'Limpiar las otras cajas de texto.
TxtHotDog.Text = ""
TxtHamburguesa.Text = ""
TxtRefresco.Text = ""
End If
End Sub
Private Sub txtHamburguesa_Change()
'Limpiando el lblTotal.
LblTotal.Caption = ""
End Sub
Private Sub txtHamburguesa_GotFocus()
TxtHamburguesa.SelStart = 0
TxtHamburguesa.SelLength = Len(TxtHamburguesa.Text)
End Sub
Private Sub txtHamburguesa_LostFocus()
If TxtHamburguesa.Text = "" Then
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 23
CantidadHamburguesa = 0
Exit Sub
End If
If IsNumeric(TxtHamburguesa.Text) Then 'Si es numérico.
If TxtHamburguesa.Text > 0 Then 'Si es positivo.
CantidadHamburguesa = TxtHamburguesa.Text 'Entonces asigna el valor a la variable.
Else
MsgBox "Entre un valor positivo", vbCritical
TxtHamburguesa.SetFocus
End If
Else
MsgBox "Entre un valor numérico", vbCritical
TxtHamburguesa.SetFocus
End If
End Sub
Private Sub txtGaseosa_Change()
LblTotal.Caption = ""
End Sub
Private Sub txtGaseosa_GotFocus()
'Para seleccionar el texto(igual en todos).
TxtGaseosa.SelStart = 0
TxtGaseosa.SelLength = Len(TxtGaseosa.Text)
End Sub
Private Sub txtGaseosa_LostFocus()
If TxtGaseosa.Text = "" Then
CantidadGaseosa = 0
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 24
Exit Sub
End If
If IsNumeric(TxtGaseosa.Text) Then 'Si es numérico.
If TxtGaseosa.Text > 0 Then 'Si es positivo.
CantidadGaseosa = TxtGaseosa.Text 'Entonces asigna el valor a la variable.
Else
MsgBox "Entre un valor positivo", vbCritical
TxtGaseosa.SetFocus
End If
Else
MsgBox "Entre un valor numérico", vbCritical
TxtGaseosa.SetFocus
End If
End Sub
Private Sub txtHotDog_Change()
LblTotal.Caption = ""
End Sub
Private Sub txtHotDog_GotFocus()
TxtHotDog.SelStart = 0
TxtHotDog.SelLength = Len(TxtHotDog.Text)
End Sub
Private Sub txtHotDog_LostFocus()
If TxtHotDog.Text = "" Then
CantidadHotDog = 0
Exit Sub
End If
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 25
If IsNumeric(TxtHotDog.Text) Then 'Si es numérico.
If TxtHotDog.Text > 0 Then 'Si es positivo.
CantidadHotDog = TxtHotDog.Text 'Entonces asigna el valor a la variable.
Else
MsgBox "Entre un valor positivo", vbCritical
TxtHotDog.SetFocus
End If
Else
MsgBox "Entre un valor numérico", vbCritical
TxtHotDog.SetFocus
End If
End Sub
Private Sub txtPapasFritas_Change()
LblTotal.Caption = ""
End Sub
Private Sub txtPapasFritas_GotFocus()
TxtPapasFritas.SelStart = 0
TxtPapasFritas.SelLength = Len(TxtPapasFritas.Text)
End Sub
Private Sub txtPapasFritas_LostFocus()
If TxtPapasFritas.Text = "" Then
CantidadPapasFritas = 0
Exit Sub
End If
If IsNumeric(TxtPapasFritas.Text) Then 'Si es numérico.
If TxtPapasFritas.Text > 0 Then 'Si es positivo.
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 26
CantidadPapasFritas = TxtPapasFritas.Text 'Entonces asigna el valor a la variable.
Else
MsgBox "Entre un valor positivo", vbCritical
TxtPapasFritas.SetFocus
End If
Else
MsgBox "Entre un valor numérico", vbCritical
TxtPapasFritas.SetFocus
End If
End Sub
Private Sub txtRefresco_Change()
LblTotal.Caption = ""
End Sub
Private Sub txtRefresco_GotFocus()
TxtRefresco.SelStart = 0
TxtRefresco.SelLength = Len(TxtRefresco.Text)
End Sub
Private Sub txtRefresco_LostFocus()
If TxtRefresco.Text = "" Then
CantidadRefresco = 0
Exit Sub
End If
If IsNumeric(TxtRefresco.Text) Then 'Si es numérico.
If TxtRefresco.Text > 0 Then 'Si es positivo.
CantidadRefresco = TxtRefresco.Text 'Entonces asigna el valor a la variable.
Else
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 27
MsgBox "Entre un valor positivo", vbCritical
TxtRefresco.SetFocus
End If
Else
MsgBox "Entre un valor numérico", vbCritical
TxtRefresco.SetFocus
End If
End Sub
Private Sub txtSandwich_Change()
LblTotal.Caption = ""
End Sub
Private Sub txtSandwich_GotFocus()
TxtSandwich.SelStart = 0
TxtSandwich.SelLength = Len(TxtSandwich.Text)
End Sub
Private Sub txtSandwich_LostFocus()
If TxtSandwich.Text = "" Then
CantidadSandwich = 0
Exit Sub
End If
If IsNumeric(TxtSandwich.Text) Then 'Si es numérico.
If TxtSandwich.Text > 0 Then 'Si es positivo.
CantidadSandwich = TxtSandwich.Text 'Entonces asigna el valor a la variable.
Else
MsgBox "Entre un valor positivo", vbCritical
TxtSandwich.SetFocus
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 28
End If
Else
MsgBox "Entre un valor numérico", vbCritical
TxtSandwich.SetFocus
End If
End Sub
Default puede tener dos valores , True o False. Si está en True, el botón será el botón por defecto
que se ejecutará cuando se presione la tecla enter.
Private Sub Form_Load()
Command1.Default = True
End Sub
Tuto para cambiar las letras a negrita en los botones
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As
Single)
'Establecer la fuente del commandButton en negrita y con subrayado
If Flag Then
Command1.Font.Bold = True
Command1.Font.Underline = True
Command1.BackColor = vbWhite
Flag = False
End If
End Sub
Eventos en Visual Basic 6.0
Kazak_anjes Software Página 29
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Quita la negrita, el subrayado, y restaura el color de fondo
If Flag = False Then
Command1.Font.Bold = False
Command1.Font.Underline = False
Command1.BackColor = vbButtonFace
Flag = True
End If
End Sub

Mais conteúdo relacionado

Mais procurados

Diseño de compiladores: Un vistazo a Ceylon-JS
Diseño de compiladores: Un vistazo a Ceylon-JSDiseño de compiladores: Un vistazo a Ceylon-JS
Diseño de compiladores: Un vistazo a Ceylon-JSEnrique Zamudio López
 
Introducción a la Progamación en Javascript. Classe 2
Introducción a la Progamación en Javascript. Classe 2Introducción a la Progamación en Javascript. Classe 2
Introducción a la Progamación en Javascript. Classe 2xjordi
 
Practica de visual basic sistema de facturación
Practica de visual basic sistema de facturaciónPractica de visual basic sistema de facturación
Practica de visual basic sistema de facturaciónmilenka796
 
Manual de shine system
Manual de shine systemManual de shine system
Manual de shine systemRafa
 
5. Interacción con el usuario: eventos y formularios
5. Interacción con el usuario: eventos y formularios5. Interacción con el usuario: eventos y formularios
5. Interacción con el usuario: eventos y formulariosLaura Folgado Galache
 
Manual de shine system
Manual de shine systemManual de shine system
Manual de shine systemRafa
 
6. Utilización del modelo de objetos del documento (DOM)
6. Utilización del modelo de objetos del documento (DOM)6. Utilización del modelo de objetos del documento (DOM)
6. Utilización del modelo de objetos del documento (DOM)Laura Folgado Galache
 
Unidad vgestion de base de datos
Unidad vgestion de base de datosUnidad vgestion de base de datos
Unidad vgestion de base de datosSol Hernández
 
Ejemplos Borland C++ Builder
Ejemplos Borland C++ BuilderEjemplos Borland C++ Builder
Ejemplos Borland C++ BuilderDarwin Durand
 

Mais procurados (18)

Diseño de compiladores: Un vistazo a Ceylon-JS
Diseño de compiladores: Un vistazo a Ceylon-JSDiseño de compiladores: Un vistazo a Ceylon-JS
Diseño de compiladores: Un vistazo a Ceylon-JS
 
Manual tecnico
Manual tecnicoManual tecnico
Manual tecnico
 
Introducción a la Progamación en Javascript. Classe 2
Introducción a la Progamación en Javascript. Classe 2Introducción a la Progamación en Javascript. Classe 2
Introducción a la Progamación en Javascript. Classe 2
 
Practica de visual basic sistema de facturación
Practica de visual basic sistema de facturaciónPractica de visual basic sistema de facturación
Practica de visual basic sistema de facturación
 
Manual de shine system
Manual de shine systemManual de shine system
Manual de shine system
 
5. Interacción con el usuario: eventos y formularios
5. Interacción con el usuario: eventos y formularios5. Interacción con el usuario: eventos y formularios
5. Interacción con el usuario: eventos y formularios
 
Semana 1 Estructuras de Control en Java
Semana 1   Estructuras de Control en JavaSemana 1   Estructuras de Control en Java
Semana 1 Estructuras de Control en Java
 
ProyectoFinal-Reporte
ProyectoFinal-ReporteProyectoFinal-Reporte
ProyectoFinal-Reporte
 
My Sql A C#
My Sql A C#My Sql A C#
My Sql A C#
 
Semana 1 Estructuras de Datos en Java
Semana 1   Estructuras de Datos en JavaSemana 1   Estructuras de Datos en Java
Semana 1 Estructuras de Datos en Java
 
Manual de shine system
Manual de shine systemManual de shine system
Manual de shine system
 
6. Utilización del modelo de objetos del documento (DOM)
6. Utilización del modelo de objetos del documento (DOM)6. Utilización del modelo de objetos del documento (DOM)
6. Utilización del modelo de objetos del documento (DOM)
 
Guia programacon formulario cambiar clave
Guia programacon formulario cambiar claveGuia programacon formulario cambiar clave
Guia programacon formulario cambiar clave
 
Guia programacion acceso al asistema
Guia programacion  acceso al asistemaGuia programacion  acceso al asistema
Guia programacion acceso al asistema
 
Unidad vgestion de base de datos
Unidad vgestion de base de datosUnidad vgestion de base de datos
Unidad vgestion de base de datos
 
Ap Is En Windows Mobile 5.0 V2.1
Ap Is En Windows Mobile 5.0 V2.1Ap Is En Windows Mobile 5.0 V2.1
Ap Is En Windows Mobile 5.0 V2.1
 
Ejemplos Borland C++ Builder
Ejemplos Borland C++ BuilderEjemplos Borland C++ Builder
Ejemplos Borland C++ Builder
 
Altas alumnos
Altas alumnosAltas alumnos
Altas alumnos
 

Semelhante a Eventos-en-visual-basic-60

Crear El Proyecto Y El Primer Formulario Con Su CodificacióN
Crear El Proyecto Y El Primer  Formulario Con Su CodificacióNCrear El Proyecto Y El Primer  Formulario Con Su CodificacióN
Crear El Proyecto Y El Primer Formulario Con Su CodificacióNjameszx
 
Crear El Proyecto Y El Primer Formulario Con Su CodificacióN
Crear El Proyecto Y El Primer  Formulario Con Su CodificacióNCrear El Proyecto Y El Primer  Formulario Con Su CodificacióN
Crear El Proyecto Y El Primer Formulario Con Su CodificacióNjameszx
 
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De ClienteFormulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De Clientejameszx
 
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De ClienteFormulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De Clientejameszx
 
Altas alumnos
Altas alumnosAltas alumnos
Altas alumnosSicohe
 
Ejercicio access+visualb
Ejercicio access+visualbEjercicio access+visualb
Ejercicio access+visualbvalen
 
codigos de algunas pantallas
codigos de algunas pantallas codigos de algunas pantallas
codigos de algunas pantallas Dania Archaga
 
Proyecto de un formulario de facturacion
Proyecto de un formulario de facturacionProyecto de un formulario de facturacion
Proyecto de un formulario de facturacionRoyer Tuesta Salas
 
Documentoaltas
DocumentoaltasDocumentoaltas
DocumentoaltaslupithaRSz
 
Sentenciasenvisualbasicnet2019
Sentenciasenvisualbasicnet2019Sentenciasenvisualbasicnet2019
Sentenciasenvisualbasicnet2019Victor Zapata
 

Semelhante a Eventos-en-visual-basic-60 (20)

Crear El Proyecto Y El Primer Formulario Con Su CodificacióN
Crear El Proyecto Y El Primer  Formulario Con Su CodificacióNCrear El Proyecto Y El Primer  Formulario Con Su CodificacióN
Crear El Proyecto Y El Primer Formulario Con Su CodificacióN
 
Crear El Proyecto Y El Primer Formulario Con Su CodificacióN
Crear El Proyecto Y El Primer  Formulario Con Su CodificacióNCrear El Proyecto Y El Primer  Formulario Con Su CodificacióN
Crear El Proyecto Y El Primer Formulario Con Su CodificacióN
 
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De ClienteFormulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
 
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De ClienteFormulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
 
Crear una solución en visual studio
Crear una solución en visual studioCrear una solución en visual studio
Crear una solución en visual studio
 
Guia no2 ado.net
Guia no2 ado.netGuia no2 ado.net
Guia no2 ado.net
 
Altas alumnos
Altas alumnosAltas alumnos
Altas alumnos
 
Ejercicio access+visualb
Ejercicio access+visualbEjercicio access+visualb
Ejercicio access+visualb
 
codigos de algunas pantallas
codigos de algunas pantallas codigos de algunas pantallas
codigos de algunas pantallas
 
VISUAL BASIC 6.0
VISUAL BASIC 6.0VISUAL BASIC 6.0
VISUAL BASIC 6.0
 
PedroMiguelSanchez
PedroMiguelSanchezPedroMiguelSanchez
PedroMiguelSanchez
 
CodigoFelizLombriz
CodigoFelizLombrizCodigoFelizLombriz
CodigoFelizLombriz
 
Codigo tarea deposito
Codigo tarea depositoCodigo tarea deposito
Codigo tarea deposito
 
Codigo tarea deposito
Codigo tarea depositoCodigo tarea deposito
Codigo tarea deposito
 
Proyecto de un formulario de facturacion
Proyecto de un formulario de facturacionProyecto de un formulario de facturacion
Proyecto de un formulario de facturacion
 
Documentoaltas
DocumentoaltasDocumentoaltas
Documentoaltas
 
Boton de eliminar
Boton de eliminarBoton de eliminar
Boton de eliminar
 
Practica
PracticaPractica
Practica
 
Sentenciasenvisualbasicnet2019
Sentenciasenvisualbasicnet2019Sentenciasenvisualbasicnet2019
Sentenciasenvisualbasicnet2019
 
Codigo proceso
Codigo procesoCodigo proceso
Codigo proceso
 

Mais de Marabely España D Juárez (10)

Sample format for writing a letter
Sample format for writing a letterSample format for writing a letter
Sample format for writing a letter
 
Formula practice worksheet
Formula practice worksheetFormula practice worksheet
Formula practice worksheet
 
Etapas de la organización
Etapas de la organizaciónEtapas de la organización
Etapas de la organización
 
21158360 visual-basic
21158360 visual-basic21158360 visual-basic
21158360 visual-basic
 
Macbeth 1
Macbeth 1Macbeth 1
Macbeth 1
 
Cuaderno de Trabajo VB 6.0
Cuaderno de Trabajo VB 6.0Cuaderno de Trabajo VB 6.0
Cuaderno de Trabajo VB 6.0
 
Almacén de datos
Almacén de datosAlmacén de datos
Almacén de datos
 
Irregular verbs list
Irregular verbs listIrregular verbs list
Irregular verbs list
 
Comparison superlatives
Comparison superlativesComparison superlatives
Comparison superlatives
 
Ejercicioexcel
EjercicioexcelEjercicioexcel
Ejercicioexcel
 

Eventos-en-visual-basic-60

  • 1. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 1 EVENTOS PARA REALIZAR ACCESO DE ENTRADA Private Sub cmdAceptar_Click() If (TxtUsuario.Text = "1234") Then Form2.Show Unload Me MsgBox ("Bienvenido a Kazak Multimedia Player"), vbInformation, "Mensaje" Else MsgBox ("Por favor inserte la contraseña correcta"), vbCritical, "¡Error!" TxtUsuario = "" TxtUsuario.SetFocus End If End Sub
  • 2. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 2 CALCULADORA Public Suma As Double Private Sub Command1_Click() Dim Valor As Double If Text1.Text = "" Then Valor = 0 Else Valor = CDbl(Text1.Text) End If Suma = Suma + Valor LblResultado.Caption = Suma Text1.Text = "" End Sub Private Sub mnumerica_Click() L.Show
  • 3. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 3 End Sub Private Sub OptDividir_Click() If Val(TxtSegundoValor.Text) = 0 Then MsgBox ("No se puede dividir por cero.") Else TxtResultado.Text = Val(TxtPrimerValor.Text) / Val(TxtSegundoValor.Text) End If End Sub Private Sub OptMultiplicar_Click() TxtResultado.Text = Val(TxtPrimerValor.Text) * Val(TxtSegundoValor.Text) End Sub Private Sub OptRestar_Click() TxtResultado.Text = Val(TxtPrimerValor.Text) - Val(TxtSegundoValor.Text) End Sub Private Sub OptSumar_Click() TxtResultado.Text = Val(TxtPrimerValor.Text) + Val(TxtSegundoValor.Text) End Sub Private Sub TxtPrimerValor_KeyPress(KeyAscii As Integer) If InStr("0123456789" & Chr(8) & Chr(13), Chr(KeyAscii)) = 0 Then KeyAscii = 0 End If End Sub
  • 4. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 4 Private Sub TxtSegundoValor_KeyPress(KeyAscii As Integer) If InStr("0123456789" & Chr(8) & Chr(13), Chr(KeyAscii)) = 0 Then KeyAscii = 0 End If End Sub PARA HACER UN REGISTRO Private Sub Command1_Click() Dim Clave As String Clave = "1234512345123451234512345" 'Verifica que la contraseña es igual a la que contiene las cajas. If TxtCaja1.Text & TxtCaja2.Text & TxtCaja3.Text & TxtCaja4.Text & TxtCaja5.Text = Clave Then MsgBox ("Contraseña Correcta.") Unload Me ' Cierra esta ventana. Else MsgBox ("Contraseña Incorrecta."), vbCritical, "Registro" TxtCaja1.SetFocus ' Hace que la primera caja reciba el enfoque. End If End Sub Private Sub Command2_Click() End End Sub
  • 5. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 5 Private Sub TxtCaja1_Change() 'Verificamos que Si la primera caja de texto tiene cinco caracteres. If Len(TxtCaja1.Text) = 5 Then TxtCaja2.SetFocus ' Saltamos a la segunda caja. End If End Sub Private Sub TxtCaja2_Change() 'Verificamos que Si la primera caja de texto tiene cinco caracteres. If Len(TxtCaja2.Text) = 5 Then TxtCaja3.SetFocus ' Saltamos a la tercera caja. End If End Sub Private Sub TxtCaja3_Change() 'Verificamos que Si la primera caja de texto tiene cinco caracteres. If Len(TxtCaja3.Text) = 5 Then TxtCaja4.SetFocus ' Saltamos a la cuarta caja. End If End Sub Private Sub TxtCaja4_Change() 'Verificamos que Si la primera caja de texto tiene cinco caracteres. If Len(TxtCaja4.Text) = 5 Then TxtCaja5.SetFocus ' Saltamos a la quinta caja. End If End Sub
  • 6. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 6 Private Sub TxtCaja5_Change() 'Verificamos que Si la cuarta caja de texto tiene cinco caracteres. 'If Len(TxtCaja5.Text) = 5 Then 'cmdRegistrar.SetFocus 'Hacemos que el botón Registrar reciba el enfoque. 'End If End Sub CAMBIO DE COLORES EN LOS LABELS Option Explicit Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Dim MoveCursor As Boolean Private Sub Command1_Click() End Sub
  • 7. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 7 Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) ' Desactiva el color de fondo de las opciones 'If Label3.BackStyle = 1 Then Label3.BackStyle = 0 'If Label4.BackStyle = 1 Then Label4.BackStyle = 0 'If Label5.BackStyle = 1 Then Label5.BackStyle = 0 'If Label6.BackStyle = 1 Then Label6.BackStyle = 0 'If Label7.BackStyle = 1 Then Label7.BackStyle = 0 MoveCursor = True End Sub Private Sub Label3_Click() FrmInscripcion.Show End Sub Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Label3.BackStyle = 0 Then Label3.BackStyle = 1 ' Permite que se establezca el color de fondo Label3.BackColor = &H8000& ' Pone el color verde 'Desactiva el color de fondo de las demás opciones Label4.BackStyle = 0 Label5.BackStyle = 0 Label6.BackStyle = 0 Label7.BackStyle = 0 End If End Sub Private Sub Label4_Click() FrmTexto.Show
  • 8. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 8 End Sub Private Sub Label4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Label4.BackStyle = 0 Then Label4.BackStyle = 1 ' Permite que se establezca el color de fondo Label4.BackColor = &H8000& ' Pone el color verde 'Desactiva el color de fondo de las demás opciones Label3.BackStyle = 0 Label5.BackStyle = 0 Label6.BackStyle = 0 Label7.BackStyle = 0 End If End Sub Private Sub Label5_Click() FrmRegistro.Show End Sub Private Sub Label5_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Label5.BackStyle = 0 Then Label5.BackStyle = 1 ' Permite que se establezca el color de fondo Label5.BackColor = &H8000& ' Pone el color verde 'Desactiva el color de fondo de las demás opciones Label3.BackStyle = 0 Label4.BackStyle = 0 Label6.BackStyle = 0 Label7.BackStyle = 0 End If
  • 9. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 9 End Sub Private Sub Label6_Click() FrmBoton.Show End Sub Private Sub Label6_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Label6.BackStyle = 0 Then Label6.BackStyle = 1 ' Permite que se establezca el color de fondo Label6.BackColor = &H8000& ' Pone el color verde 'Desactiva el color de fondo de las demás opciones Label3.BackStyle = 0 Label4.BackStyle = 0 Label5.BackStyle = 0 Label7.BackStyle = 0 End If End Sub Private Sub Label7_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Label7.BackStyle = 0 Then Label7.BackStyle = 1 ' Permite que se establezca el color de fondo Label7.BackColor = &H8000& ' Pone el color verde 'Desactiva el color de fondo de las demás opciones Label3.BackStyle = 0 Label4.BackStyle = 0 Label5.BackStyle = 0 Label6.BackStyle = 0 End If
  • 10. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 10 End Sub 'en las etiquetas seleccionadas hemos seleccionado en las 'propiedades Autosize=true y en BackStyle= 0 – Transparent INSCRIPCIONES SOLO PARA MAYORES DE EDAD Private Sub Command1_Click() 'Verifica si la caja de texto Nombre esta vacía. If Len(Trim(TxtNombre.Text)) = 0 Then MsgBox ("Debe introducir el Nombre.") TxtNombre.SetFocus ' Hace que la caja reciba el enfoque. 'Verifica si la caja de texto Apellido esta vacía. ElseIf Len(Trim(TxtApellido.Text)) = 0 Then MsgBox ("Debe introducir el Apellido.") TxtApellido.SetFocus ' Hace que la caja reciba el enfoque. 'Verifica si la caja de texto Cédula esta vacía. ElseIf Len(Trim(TxtCedula.Text)) = 0 Then MsgBox ("Debe introducir la Cedula.") TxtCedula.SetFocus ' Hace que la caja reciba el enfoque. 'Verifica si la caja de texto Edad esta vacía. ElseIf Len(Trim(TxtEdad.Text)) = 0 Then
  • 11. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 11 MsgBox ("Debe introducir la Edad.") TxtEdad.SetFocus 'Verifica si la persona es menor de Edad. ElseIf Val(TxtEdad.Text) < 18 Then 'MsgBox(“No se registran personas menores de edad.”) TxtEdad.SetFocus 'Verifica si la caja de texto Dirección esta vacía. ElseIf Len(Trim(TxtDireccion.Text)) = 0 Then MsgBox ("Debe introducir la Dirección.") TxtDireccion.SetFocus ' Hace que la caja reciba el enfoque. Else 'Aquí se escribe la codificación para almacenar los datos en la Base de datos. 'En nuestro caso mostraremos un mensaje para hacer un simulacro. MsgBox ("El registro ha sido almacenado satisfactoriamente.") 'Limpiamos las cajas. TxtNombre.Text = "" TxtApellido.Text = "" TxtCedula.Text = "" TxtEdad.Text = "" TxtTelefono.Text = "" TxtDireccion.Text = "" End If End Sub Private Sub Command2_Click() Dim respuesta
  • 12. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 12 respuesta = MsgBox("¿Desea salir de la aplicación?", vbCritical _ + vbYesNo, "Cerrar") If respuesta = vbYes Then Unload Me End If End Sub Private Sub CmdRegistrar_Click() End Sub Private Sub Command3_Click() CommonDialog1.Filter = "Video (*.mpeg) *.mpeg|Musica (*.mp3) *.mp3|Todos los archivos (*.*) *.*|" CommonDialog1.FilterIndex = 1 CommonDialog1.ShowOpen LbNom.Caption = CommonDialog1.FileTitle MediaPlayer1.FileName = LbNom End Sub Private Sub TxtApellido_Validate(Cancel As Boolean) 'Verifica si la caja de texto esta vacía. If Len(Trim(TxtApellido.Text)) = 0 Then MsgBox ("Debe introducir el Apellido."), vbCritical Cancel = True ' Hace que el enfoque NO pase a otro control. End If End Sub
  • 13. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 13 Private Sub TxtCedula_Validate(Cancel As Boolean) 'Verifica si la caja de texto esta vacía. If Len(Trim(TxtCedula.Text)) = 0 Then MsgBox ("Debe introducir la Cédula."), vbCritical Cancel = True ' Hace que el enfoque NO pase a otro control. End If TxtCedula.SetFocus End Sub Private Sub TxtDireccion_Validate(Cancel As Boolean) 'Verifica si la caja de texto esta vacía. If Len(Trim(TxtDireccion.Text)) = 0 Then MsgBox ("Debe introducir la Dirección."), vbCritical Cancel = True ' Hace que el enfoque NO pase a otro control. End If End Sub Private Sub TxtEdad_Validate(Cancel As Boolean) 'Verifica si la caja de texto esta vacía. If Len(Trim(TxtEdad.Text)) = 0 Then MsgBox ("Debe introducir la Edad."), vbCritical Cancel = True ' Hace que el enfoque NO pase a otro control. 'Verifica que la edad cumpla con el criterio establecido. ElseIf Val(TxtEdad.Text) < 18 Then MsgBox ("No se registran menores de edad."), vbCritical, "Mensaje"
  • 14. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 14 Cancel = True ' Hace que el enfoque NO pase a otro control. End If End Sub Private Sub TxtNombre_Validate(Cancel As Boolean) 'Verifica si la caja de texto esta vacía. If Len(Trim(TxtNombre.Text)) = 0 Then MsgBox ("Debe introducir el Nombre."), vbCritical, "Mensaje" Cancel = True ' Hace que el enfoque NO pase a otro control. End If End Sub IMPRIMIR EL FORMULARIO
  • 15. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 15 Private Sub Command1_Click() Printer.Orientation = 1 ' La orientación del papel es vertical Printer.FontSize = 12 'Tamaño de la letra Printer.Print 'Un renglón en blanco o salto de carro Printer.Print Printer.Print Printer.Print Tab(15); Label1.Caption; Tab(30); Text1.Text 'Aquí damos la orden de impresión del caption de la label1 a 15 espacios 'del margen izquerdo y luego a 30 espacios del margen izquierdo el 'contenido del texto. Printer.Print Printer.Print Printer.Print Tab(15); Label2.Caption; Tab(30); Text2.Text Printer.Print Printer.Print Printer.Print Tab(15); Label3.Caption; Tab(30); Text3.Text Printer.Print Printer.Print Printer.Print Printer.Print Tab(15); Label4.Caption; Tab(30); Text4.Text Printer.Print Printer.Print Printer.Print Tab(15); Label5.Caption; Tab(30); Text5.Text
  • 16. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 16 Printer.Print Printer.Print Printer.Print Tab(15); Label6.Caption; Tab(30); Text6.Text Printer.EndDoc 'damos por terminada la impresión End Sub Private Sub Command2_Click() Form2.Show End Sub Private Sub Command3_Click() Form3.Show End Sub COBRO DE SERVICIOS DE COMIDA
  • 17. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 17 Dim Sandwich As Single Dim Gaseosa As Single Dim Refresco As Single Dim PapasFritas As Single 'Declaración de variables para la cantidad de cada una. Dim CantidadHamburguesa As Integer Dim CantidadHotDog As Integer Dim CantidadSandwich As Integer Dim CantidadGaseosa As Integer Dim CantidadRefresco As Integer Dim CantidadPapasFritas As Integer Private Sub cmdCalcular_Click() 'Multiplicando la cantidad por el precio y sumando para hallar el total. Total = (CantidadHamburguesa * Hamburguesa) + (CantidadHotDog * HotDog) + _ (CantidadSandwich * Sandwich) + (CantidadGaseosa * Gaseosa) + _ (CantidadRefresco * Refresco) + (CantidadPapasFritas * PapasFritas) LblTotal.Caption = "$ " & Total End Sub Private Sub cmdSalir_Click() End End Sub Private Sub Form_Load() 'Inicializar las variables 'Precio de los productos Hamburguesa = 20.5 HotDog = 19.25
  • 18. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 18 Sandwich = 17.5 PapasFritas = 4.5 Refresco = 4 Gaseosa = 5 End Sub Private Sub optOtroPedido_Click() 'Limpiar el label lblTotal. LblTotal.Caption = "" 'Inicializar las variables. CantidadHamburguesa = 0 CantidadGaseosa = 0 CantidadPapasFritas = 0 CantidadHotDog = 0 CantidadSandwich = 0 CantidadRefresco = 0 'Habilitar todas las cajas de texto para poder entrar datos en todas. TxtHamburguesa.Enabled = True TxtHotDog.Enabled = True TxtSandwich.Enabled = True TxtGaseosa.Enabled = True TxtRefresco.Enabled = True TxtPapasFritas.Enabled = True 'Limpiar todas las cajas de texto. TxtHamburguesa.Text = "" TxtHotDog.Text = "" TxtSandwich.Text = ""
  • 19. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 19 TxtGaseosa.Text = "" TxtRefresco.Text = "" TxtPapasFritas.Text = "" End Sub Private Sub optPedido1_Click() 'Hamburguesas,Gaseosa y Papas Fritas. 'Limpiar el label lblTotal. LblTotal.Caption = "" If OptPedido1.Value Then 'si esta chequeado. 'Inicializar las variables. CantidadHamburguesa = 1 CantidadGaseosa = 1 CantidadPapasFritas = 1 CantidadHotDog = 0 CantidadSandwich = 0 CantidadRefresco = 0 'Inicializar la caja de texto. TxtHamburguesa.Text = CantidadHamburguesa TxtGaseosa.Text = CantidadGaseosa TxtPapasFritas.Text = CantidadPapasFritas 'Habilitar las cajas de texto. TxtHamburguesa.Enabled = True TxtGaseosa.Enabled = True TxtPapasFritas.Enabled = True 'Deshabilitar las otras cajas de texto. TxtHotDog.Enabled = False
  • 20. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 20 TxtSandwich.Enabled = False TxtRefresco.Enabled = False 'Limpiar las otras cajas de texto. TxtHotDog.Text = "" TxtSandwich.Text = "" TxtRefresco.Text = "" End If End Sub Private Sub optPedido2_Click() 'HotDog,Gaseosa y Papas Fritas. 'Limpiar el label lblTotal. LblTotal.Caption = "" If OptPedido2.Value Then 'Inicializar las variables. CantidadHotDog = 1 CantidadGaseosa = 1 CantidadPapasFritas = 1 CantidadHamburguesa = 0 CantidadSandwich = 0 CantidadRefresco = 0 'Inicializar la caja de texto. TxtHotDog.Text = CantidadHotDog TxtGaseosa.Text = CantidadGaseosa TxtPapasFritas.Text = CantidadPapasFritas 'Habilitar las cajas de texto. TxtHotDog.Enabled = True
  • 21. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 21 TxtGaseosa.Enabled = True TxtPapasFritas.Enabled = True 'Deshabilitar las otras cajas de texto. TxtHamburguesa.Enabled = False TxtSandwich.Text = False TxtRefresco.Text = False 'Limpiar las otras cajas de texto. TxtHamburguesa.Text = "" TxtSandwich.Text = "" TxtRefresco.Text = "" End If End Sub Private Sub optPedido3_Click() 'Sanwich,Gaseosa y Papas Fritas. 'Limpiar el label lblTotal LblTotal.Caption = "" If OptPedido3.Value Then 'Inicializar las variables CantidadSandwich = 1 CantidadGaseosa = 1 CantidadPapasFritas = 1 CantidadHamburguesa = 0 CantidadHotDog = 0 CantidadRefresco = 0 'Inicializar la caja de texto TxtSandwich.Text = CantidadSandwich
  • 22. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 22 TxtGaseosa.Text = CantidadGaseosa TxtPapasFritas.Text = CantidadPapasFritas 'Habilitar las cajas de texto TxtSandwich.Enabled = True TxtGaseosa.Enabled = True TxtPapasFritas.Enabled = True 'Deshabilitar las otras cajas de texto. TxtHotDog.Enabled = False TxtHamburguesa.Enabled = False TxtRefresco.Enabled = False 'Limpiar las otras cajas de texto. TxtHotDog.Text = "" TxtHamburguesa.Text = "" TxtRefresco.Text = "" End If End Sub Private Sub txtHamburguesa_Change() 'Limpiando el lblTotal. LblTotal.Caption = "" End Sub Private Sub txtHamburguesa_GotFocus() TxtHamburguesa.SelStart = 0 TxtHamburguesa.SelLength = Len(TxtHamburguesa.Text) End Sub Private Sub txtHamburguesa_LostFocus() If TxtHamburguesa.Text = "" Then
  • 23. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 23 CantidadHamburguesa = 0 Exit Sub End If If IsNumeric(TxtHamburguesa.Text) Then 'Si es numérico. If TxtHamburguesa.Text > 0 Then 'Si es positivo. CantidadHamburguesa = TxtHamburguesa.Text 'Entonces asigna el valor a la variable. Else MsgBox "Entre un valor positivo", vbCritical TxtHamburguesa.SetFocus End If Else MsgBox "Entre un valor numérico", vbCritical TxtHamburguesa.SetFocus End If End Sub Private Sub txtGaseosa_Change() LblTotal.Caption = "" End Sub Private Sub txtGaseosa_GotFocus() 'Para seleccionar el texto(igual en todos). TxtGaseosa.SelStart = 0 TxtGaseosa.SelLength = Len(TxtGaseosa.Text) End Sub Private Sub txtGaseosa_LostFocus() If TxtGaseosa.Text = "" Then CantidadGaseosa = 0
  • 24. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 24 Exit Sub End If If IsNumeric(TxtGaseosa.Text) Then 'Si es numérico. If TxtGaseosa.Text > 0 Then 'Si es positivo. CantidadGaseosa = TxtGaseosa.Text 'Entonces asigna el valor a la variable. Else MsgBox "Entre un valor positivo", vbCritical TxtGaseosa.SetFocus End If Else MsgBox "Entre un valor numérico", vbCritical TxtGaseosa.SetFocus End If End Sub Private Sub txtHotDog_Change() LblTotal.Caption = "" End Sub Private Sub txtHotDog_GotFocus() TxtHotDog.SelStart = 0 TxtHotDog.SelLength = Len(TxtHotDog.Text) End Sub Private Sub txtHotDog_LostFocus() If TxtHotDog.Text = "" Then CantidadHotDog = 0 Exit Sub End If
  • 25. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 25 If IsNumeric(TxtHotDog.Text) Then 'Si es numérico. If TxtHotDog.Text > 0 Then 'Si es positivo. CantidadHotDog = TxtHotDog.Text 'Entonces asigna el valor a la variable. Else MsgBox "Entre un valor positivo", vbCritical TxtHotDog.SetFocus End If Else MsgBox "Entre un valor numérico", vbCritical TxtHotDog.SetFocus End If End Sub Private Sub txtPapasFritas_Change() LblTotal.Caption = "" End Sub Private Sub txtPapasFritas_GotFocus() TxtPapasFritas.SelStart = 0 TxtPapasFritas.SelLength = Len(TxtPapasFritas.Text) End Sub Private Sub txtPapasFritas_LostFocus() If TxtPapasFritas.Text = "" Then CantidadPapasFritas = 0 Exit Sub End If If IsNumeric(TxtPapasFritas.Text) Then 'Si es numérico. If TxtPapasFritas.Text > 0 Then 'Si es positivo.
  • 26. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 26 CantidadPapasFritas = TxtPapasFritas.Text 'Entonces asigna el valor a la variable. Else MsgBox "Entre un valor positivo", vbCritical TxtPapasFritas.SetFocus End If Else MsgBox "Entre un valor numérico", vbCritical TxtPapasFritas.SetFocus End If End Sub Private Sub txtRefresco_Change() LblTotal.Caption = "" End Sub Private Sub txtRefresco_GotFocus() TxtRefresco.SelStart = 0 TxtRefresco.SelLength = Len(TxtRefresco.Text) End Sub Private Sub txtRefresco_LostFocus() If TxtRefresco.Text = "" Then CantidadRefresco = 0 Exit Sub End If If IsNumeric(TxtRefresco.Text) Then 'Si es numérico. If TxtRefresco.Text > 0 Then 'Si es positivo. CantidadRefresco = TxtRefresco.Text 'Entonces asigna el valor a la variable. Else
  • 27. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 27 MsgBox "Entre un valor positivo", vbCritical TxtRefresco.SetFocus End If Else MsgBox "Entre un valor numérico", vbCritical TxtRefresco.SetFocus End If End Sub Private Sub txtSandwich_Change() LblTotal.Caption = "" End Sub Private Sub txtSandwich_GotFocus() TxtSandwich.SelStart = 0 TxtSandwich.SelLength = Len(TxtSandwich.Text) End Sub Private Sub txtSandwich_LostFocus() If TxtSandwich.Text = "" Then CantidadSandwich = 0 Exit Sub End If If IsNumeric(TxtSandwich.Text) Then 'Si es numérico. If TxtSandwich.Text > 0 Then 'Si es positivo. CantidadSandwich = TxtSandwich.Text 'Entonces asigna el valor a la variable. Else MsgBox "Entre un valor positivo", vbCritical TxtSandwich.SetFocus
  • 28. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 28 End If Else MsgBox "Entre un valor numérico", vbCritical TxtSandwich.SetFocus End If End Sub Default puede tener dos valores , True o False. Si está en True, el botón será el botón por defecto que se ejecutará cuando se presione la tecla enter. Private Sub Form_Load() Command1.Default = True End Sub Tuto para cambiar las letras a negrita en los botones Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Establecer la fuente del commandButton en negrita y con subrayado If Flag Then Command1.Font.Bold = True Command1.Font.Underline = True Command1.BackColor = vbWhite Flag = False End If End Sub
  • 29. Eventos en Visual Basic 6.0 Kazak_anjes Software Página 29 Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Quita la negrita, el subrayado, y restaura el color de fondo If Flag = False Then Command1.Font.Bold = False Command1.Font.Underline = False Command1.BackColor = vbButtonFace Flag = True End If End Sub