eventos en visual basic 6.0
TRANSCRIPT
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