Eventos en Visual Basic 6.0

of 29 /29
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

Embed Size (px)

Transcript of Eventos en Visual Basic 6.0

Eventos en Visual Basic 6.0

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 contrasea correcta"), vbCritical, "Error!" TxtUsuario = "" TxtUsuario.SetFocus End If End Sub

Kazak_anjes Software

Pgina 1

Eventos en Visual Basic 6.0

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 Kazak_anjes Software Pgina 2

Eventos en Visual Basic 6.0End 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

Kazak_anjes Software

Pgina 3

Eventos en Visual Basic 6.0Private 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 contrasea es igual a la que contiene las cajas. If TxtCaja1.Text & TxtCaja2.Text & TxtCaja3.Text & TxtCaja4.Text & TxtCaja5.Text = Clave Then MsgBox ("Contrasea Correcta.") Unload Me ' Cierra esta ventana. Else MsgBox ("Contrasea Incorrecta."), vbCritical, "Registro" TxtCaja1.SetFocus ' Hace que la primera caja reciba el enfoque. End If End Sub

Private Sub Command2_Click() End End Sub Kazak_anjes Software Pgina 4

Eventos en Visual Basic 6.0

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 Kazak_anjes Software Pgina 5

Eventos en Visual Basic 6.0

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 botn 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

Kazak_anjes Software

Pgina 6

Eventos en Visual Basic 6.0Private 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 dems opciones Label4.BackStyle = 0 Label5.BackStyle = 0 Label6.BackStyle = 0 Label7.BackStyle = 0 End If End Sub

Private Sub Label4_Click() FrmTexto.Show Kazak_anjes Software Pgina 7

Eventos en Visual Basic 6.0End 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 dems 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 dems opciones Label3.BackStyle = 0 Label4.BackStyle = 0 Label6.BackStyle = 0 Label7.BackStyle = 0 End If Kazak_anjes Software Pgina 8

Eventos en Visual Basic 6.0End 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 dems 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 dems opciones Label3.BackStyle = 0 Label4.BackStyle = 0 Label5.BackStyle = 0 Label6.BackStyle = 0 End If Kazak_anjes Software Pgina 9

Eventos en Visual Basic 6.0End 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 vaca. 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 vaca. 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 Cdula esta vaca. 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 vaca. ElseIf Len(Trim(TxtEdad.Text)) = 0 ThenKazak_anjes Software Pgina 10

Eventos en Visual Basic 6.0MsgBox ("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 Direccin esta vaca. ElseIf Len(Trim(TxtDireccion.Text)) = 0 Then MsgBox ("Debe introducir la Direccin.") TxtDireccion.SetFocus ' Hace que la caja reciba el enfoque. Else 'Aqu se escribe la codificacin 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

Kazak_anjes Software

Pgina 11

Eventos en Visual Basic 6.0respuesta = MsgBox("Desea salir de la aplicacin?", 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 vaca. 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 SubKazak_anjes Software Pgina 12

Eventos en Visual Basic 6.0

Private Sub TxtCedula_Validate(Cancel As Boolean) 'Verifica si la caja de texto esta vaca. If Len(Trim(TxtCedula.Text)) = 0 Then MsgBox ("Debe introducir la Cdula."), 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 vaca. If Len(Trim(TxtDireccion.Text)) = 0 Then MsgBox ("Debe introducir la Direccin."), 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 vaca. 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"

Kazak_anjes Software

Pgina 13

Eventos en Visual Basic 6.0Cancel = 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 vaca. 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

Kazak_anjes Software

Pgina 14

Eventos en Visual Basic 6.0Private Sub Command1_Click() Printer.Orientation = 1 ' La orientacin del papel es vertical Printer.FontSize = 12 'Tamao de la letra Printer.Print 'Un rengln 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 impresin 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

Kazak_anjes Software

Pgina 15

Eventos en Visual Basic 6.0Printer.Print Printer.Print Printer.Print Tab(15); Label6.Caption; Tab(30); Text6.Text Printer.EndDoc 'damos por terminada la impresin End Sub

Private Sub Command2_Click() Form2.Show End Sub

Private Sub Command3_Click() Form3.Show End Sub

COBRO DE SERVICIOS DE COMIDA

Kazak_anjes Software

Pgina 16

Eventos en Visual Basic 6.0Dim Sandwich As Single Dim Gaseosa As Single Dim Refresco As Single Dim PapasFritas As Single 'Declaracin 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

Kazak_anjes Software

Pgina 17

Eventos en Visual Basic 6.0Sandwich = 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 = ""

Kazak_anjes Software

Pgina 18

Eventos en Visual Basic 6.0TxtGaseosa.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

Kazak_anjes Software

Pgina 19

Eventos en Visual Basic 6.0TxtSandwich.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

Kazak_anjes Software

Pgina 20

Eventos en Visual Basic 6.0TxtGaseosa.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

Kazak_anjes Software

Pgina 21

Eventos en Visual Basic 6.0TxtGaseosa.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

Kazak_anjes Software

Pgina 22

Eventos en Visual Basic 6.0CantidadHamburguesa = 0 Exit Sub End If If IsNumeric(TxtHamburguesa.Text) Then 'Si es numrico. 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 numrico", 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

Kazak_anjes Software

Pgina 23

Eventos en Visual Basic 6.0Exit Sub End If If IsNumeric(TxtGaseosa.Text) Then 'Si es numrico. 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 numrico", 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

Kazak_anjes Software

Pgina 24

Eventos en Visual Basic 6.0If IsNumeric(TxtHotDog.Text) Then 'Si es numrico. 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 numrico", 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 numrico. If TxtPapasFritas.Text > 0 Then 'Si es positivo.

Kazak_anjes Software

Pgina 25

Eventos en Visual Basic 6.0CantidadPapasFritas = 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 numrico", 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 numrico. If TxtRefresco.Text > 0 Then 'Si es positivo. CantidadRefresco = TxtRefresco.Text 'Entonces asigna el valor a la variable. Else

Kazak_anjes Software

Pgina 26

Eventos en Visual Basic 6.0MsgBox "Entre un valor positivo", vbCritical TxtRefresco.SetFocus End If Else MsgBox "Entre un valor numrico", 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 numrico. 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

Kazak_anjes Software

Pgina 27

Eventos en Visual Basic 6.0End If Else MsgBox "Entre un valor numrico", vbCritical TxtSandwich.SetFocus End If End Sub

Default puede tener dos valores , True o False. Si est en True, el botn ser el botn 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

Kazak_anjes Software

Pgina 28

Eventos en Visual Basic 6.0

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

Kazak_anjes Software

Pgina 29