miércoles, 3 de junio de 2009

Ejemplo 01:

Public Class Form1

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim salir As MsgBoxResult
salir = MsgBox("Desea salir del programa", MsgBoxStyle.YesNo, "Mi programa")
'aparece una ventana de opciones si o no
If salir = MsgBoxResult.No Then
e.Cancel = True
'e.cancel desactiva la salida
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.btncalc.Enabled = False
Me.btnnuevo.Enabled = False
End Sub
Function minus(ByVal a As Integer) As Boolean
If a >= 97 And a <= 122 Then
minus = True
Else
minus = False
End If
End Function
Function mayus(ByVal a As Integer) As Boolean
If a >= 65 And a <= 90 Then
mayus = True
Else
mayus = False
End If
End Function
Function especial(ByVal a As Integer) As Boolean

If a = 255 Or a = 233 Or a = 237 Or a = 13 Or a = 243 Or a = 250 Or a = 8 Or a = 27 Or a = 32 Or a = 241 Or a = 209 Then
especial = True
Else
especial = False
End If
End Function
Function numeros(ByVal a As Integer) As Boolean
If a >= 48 And a <= 57 Then
numeros = True
Else
numeros = False
End If
End Function

Private Sub txtnombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtnombre.KeyPress
Static p As Boolean
If Asc(e.KeyChar) = 13 Then 'si presiona enter entoces
Me.txtedad.Focus()
End If
If Asc(e.KeyChar) = 32 Then ' si preciona espacio
p = True
Else
' si ingresa cualquiera de estas condiciones((funciones))
If minus(Asc(e.KeyChar)) Or mayus(Asc(e.KeyChar)) Or especial(Asc(e.KeyChar)) Then
'________________________________________________________
If Trim(Me.txtnombre.Text) = "" Or p Then ' si encuentra algun espacio
e.KeyChar = UCase(e.KeyChar) 'Combierte todo a MAYUSCULAS
Else
e.KeyChar = LCase(e.KeyChar) 'Combierte todo a minusculas
End If
p = False
'________________________________________________________
Else
'muestra el mensaje de error
MsgBox("Te equibocaste; El Dato Ingresado es Invalido", MsgBoxStyle.Critical, "Mensajes del Sistema..")
e.KeyChar = ChrW(0) 'borra lo almacenado en la variable
'-------------------- el cero indica que es NULO o NADA
End If
End If
End Sub

Private Sub txtedad_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtedad.KeyPress
If Asc(e.KeyChar) = 13 Then
Dim n As Integer
If Trim(Me.txtedad.Text) = "" Then
MsgBox("Es necesario que ingreses algun DATO", MsgBoxStyle.Critical, "Mensaje del Sistema")
Else
n = Me.txtedad.Text
'______________________________________________________-
If n >= 18 And n <= 65 Then
Me.txtsexo.Focus()
Else
MsgBox("Solo se permite la edad entre 18-65 años", MsgBoxStyle.Critical, "Mensajes del Sistema")
Me.txtedad.Text = ""
n = 0
End If
'_______________________________________________________-
End If

End If
End Sub

Private Sub txtsexo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtsexo.KeyPress
If Asc(e.KeyChar) = 13 Then

If Me.txtsexo.Text = "H" Or Me.txtsexo.Text = "h" Or Me.txtsexo.Text = "M" Or Me.txtsexo.Text = "m" Then

Me.txtsueldo.Focus()
Else
MsgBox("solo se permiten los simbolos H= hombre; M= mujer", MsgBoxStyle.Critical, "Mensaje del Sistema")
Me.txtsexo.Text = ""
End If
End If
End Sub
Dim s As Integer
Private Sub txtsueldo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtsueldo.KeyPress
If Asc(e.KeyChar) = 13 Then

'*************************************
If Trim(Me.txtsueldo.Text) = "" Then
MsgBox("Es necesario que ingreses algun DATO", MsgBoxStyle.Critical, "Mensaje del Sistema")
Else
s = Me.txtsueldo.Text
'_________________________________________________
If s >= 1000 And s <= 2000 Then
If Trim(Me.txtnombre.Text) = "" Or Trim(Me.txtedad.Text) = "" Or Trim(Me.txtsexo.Text) = "" Or Trim(Me.txtsueldo.Text) = "" Then
MsgBox("Es necesario que ingreses todos los DATOS", MsgBoxStyle.Critical, "Mensaje del Sistema")
Me.txtnombre.Focus()
Else
Me.btncalc.Enabled = True
Me.btnnuevo.Enabled = True
Me.btncalc.Focus()
End If

Me.btncalc.Focus()
Else
MsgBox("Solo se permiten Valores entre 1000-2000", MsgBoxStyle.Critical, "Mensaje del Sistema")
Me.txtsueldo.Text = ""
End If
'_________________________________________________
End If
'***********************************************************
End If
End Sub

Private Sub btnsalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsalir.Click
Close()
End Sub

Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnuevo.Click
Me.txtnombre.Text = ""
Me.txtedad.Text = ""
Me.txtsexo.Text = ""
Me.txtsueldo.Text = ""
Me.lblgrati.Text = ""
Me.lbldesc.Text = ""
Me.lbltotal.Text = ""
Me.txtnombre.Focus()
End Sub
Dim g As Integer
Dim d As Integer
Private Sub btncalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalc.Click

'______________________________________________________________
If Me.txtsexo.Text = "h" Or Me.txtsexo.Text = "H" Then
If Me.txtedad.Text >= 30 And Me.txtedad.Text <= 35 Then
g = Me.txtsueldo.Text * 0.15
Me.lblgrati.Text = g
Else
Me.lblgrati.Text = "0"
End If
End If
'______________________________________________________________

If Me.txtsexo.Text = "m" Or Me.txtsexo.Text = "M" Then
If Me.txtedad.Text >= 18 And Me.txtedad.Text <= 65 Then
d = Me.txtsueldo.Text * 0.5
Me.lbldesc.Text = d
Else
Me.lbldesc.Text = "0"
End If
End If
'______________________________________________________________
Dim t As Integer
t = (s + g - d)
Me.lbltotal.Text = t
Me.btnnuevo.Focus()
End Sub
End Class



No hay comentarios:

Publicar un comentario

Dejame un Comentario: