jueves, 3 de mayo de 2012

Primer - Ultimo dia del mes



Option Explicit On
Public Class form_dia_mes
    Function nombredia(ByVal dia As Integer)
        Select Case dia
            Case 1 : nombredia = "Domingo"
            Case 2 : nombredia = "Lunes"
            Case 3 : nombredia = "Martes"
            Case 4 : nombredia = "Miercoles"
            Case 5 : nombredia = "Jueves"
            Case 6 : nombredia = "Viernes"
            Case 7 : nombredia = "Sabado"
        End Select
    End Function
    Private Sub Btnmostrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmostrar.Click
        Dim diaultimo, diaprimero As Integer
        Dim fecha As Date
        fecha = Microsoft.VisualBasic.DateValue(DateTimePicker1.Value)
        Dim Primer As Date
        Dim Ultimo As Date
        Primer = DateSerial(Year(fecha), Month(fecha) + 0, 1)
        Ultimo = DateSerial(Year(fecha), Month(fecha) + 1, 0)
        diaprimero = Microsoft.VisualBasic.Weekday(Primer)
        diaultimo = Microsoft.VisualBasic.Weekday(Ultimo)
        txtultimo.Text = nombredia(diaultimo)
        txtprimero.Text = nombredia(diaprimero)
        Dim dia As New Date
        dia = Microsoft.VisualBasic.DateValue(DateTimePicker1.Value).ToShortDateString
        dia = dia.AddDays(-dia.Day + 1)
        txtdiaprimero.Text = dia
        dia = dia.AddDays(-dia.Day + 1).AddMonths(1).AddDays(-1)
        txtdiaultimo.Text = dia
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim salida As Integer = MsgBox("Desea Salir?",
        MsgBoxStyle.YesNo + 32, "Mensaje al usuario")
        If salida = 6 Then
            Me.Close()
        End If
    End Sub
End Class

RETO 6 – Factura



Public Class frm_Factura
Dim Random As New Random()
    Dim numero As Int64 = Random.Next(100000000, 999999999)
    Private Sub frm_Factura_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.txtdia.Text = Microsoft.VisualBasic.Day(DateTimePicker1.Value)
        Me.txtmes.Text = Microsoft.VisualBasic.Month(DateTimePicker1.Value)
        Me.txtaño.Text = Microsoft.VisualBasic.Year(DateTimePicker1.Value)
        cboariculos.Items.Add("Camisetas")
        cboariculos.Items.Add("Short")
        cboariculos.Items.Add("Buzos")
        cboariculos.Items.Add("Medias")
        cboariculos.Items.Add("Casacas")
        cboariculos.Items.Add("Gorros")
        cboariculos.Items.Add("Maletines")
        lblruc.Text = "R.U.C :" & numero
    End Sub

    Private Sub cboariculos_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboariculos.SelectedIndexChanged
        Select Case cboariculos.SelectedIndex
            Case 0
                txtprecio.Text = 40
            Case 1
                txtprecio.Text = 25
            Case 2
                txtprecio.Text = 140
            Case 3
                txtprecio.Text = 15
            Case 4
                txtprecio.Text = 60
            Case 5
                txtprecio.Text = 35
            Case 6
                txtprecio.Text = 70
        End Select
    End Sub
    Private Sub btningresar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btningresar.Click
        Dim subtotal As Integer
        subtotal = NUDcantidad.Value * Val(txtprecio.Text)
        lstcantidad.Items.Add(Val(NUDcantidad.Value))
        lstdescripcion.Items.Add(cboariculos.SelectedItem)
        lstpunitario.Items.Add(Val(txtprecio.Text))
        lstptotal.Items.Add(subtotal)
    End Sub

 Private Sub btncalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalcular.Click
        Dim total As Double
        Dim Elementos_lista As Double
        Elementos_lista = lstptotal.Items.Count - 1
        total = SumarElementos(Elementos_lista)
        txtigv.Text = total * 0.19
        txttotal.Text = Val(total) + Val(txtigv.Text)
    End Sub
    Public Function SumarElementos(ByVal Lista As Integer) As Integer
        Dim i As Integer
        Dim Suma As Integer
        Suma = 0
        For i = 0 To lstptotal.Items.Count - 1
            Suma = Suma + lstptotal.Items(i)
            SumarElementos = Suma
        Next
    End Function

    Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click
        Dim m As Integer = lstdescripcion.SelectedIndex
        lstdescripcion.Items.RemoveAt(m)
        lstcantidad.Items.RemoveAt(m)
        lstptotal.Items.RemoveAt(m)
        lstpunitario.Items.RemoveAt(m)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Eliminar(lstdescripcion)
    End Sub
    Function Eliminar(ByVal LB As ListBox) As Int32
        Dim i As Int32
        Dim j As Int32
        Dim n As Int32
        For i = 0 To LB.Items.Count - 2 ' Recorre los items (compara empezando desde el primero , de abajo hacia arriba) 
            For j = LB.Items.Count - 1 To i + 1 Step -1
                If LB.Items(i).ToString = LB.Items(j).ToString Then ' ... si es el mismo
                    LB.Items.RemoveAt(j) ' elimina el elemento indicando el índice
                    lstpunitario.Items.RemoveAt(j)
                    lstcantidad.Items.RemoveAt(j)
                    lstptotal.Items.RemoveAt(j)
                End If
            Next
        Next
        Return n ' retorna los eliminados 
    End Function


    Private Sub txtnombre_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtnombre.Validating
        If txtnombre.Text.Length = 0 Then
            ErrorProvider1.SetError(Me.txtnombre, "Ingrese Nombre")
        Else
            ErrorProvider1.SetError(Me.txtnombre, "")
        End If

    End Sub

    Private Sub txtdireccion_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtdireccion.Validating
        If txtdireccion.Text.Length = 0 Then
            ErrorProvider1.SetError(Me.txtdireccion, "Ingrese Dirección")
        Else
            ErrorProvider1.SetError(Me.txtdireccion, "")
        End If
    End Sub
End Class

RETO 6 – Inscripción de Alumnos



Public Class Form1

    Inherits System.Windows.Forms.Form
    Public KeyAscii As Short
    Dim sexo As String
    Dim Random As New Random()
    Dim numero As Integer = Random.Next(1, 400)
    Dim especialidad As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        NUDedad.Minimum = 16
        NUDedad.Maximum = 60
        cbocolegio.Items.Add("Nacional")
        cbocolegio.Items.Add("Parroquial")
        cbocolegio.Items.Add("Particular")
        cboespecialidad.Items.Add("Informatica")
        cboespecialidad.Items.Add("Electronica")
        cboespecialidad.Items.Add("Contabilidad")
        txtcuota.Text = 1
        txtseccion.MaxLength = 1
    End Sub

    Function SoloLETRAS(ByVal KeyAscii As Integer) As Integer
        KeyAscii = Asc(UCase(Chr(KeyAscii))) 'Transformar letras minusculas a Mayúsculas Intercepta un código ASCII recibido admitiendo solamente letras, además: deja pasar sin afectar si recibe tecla de Backspace o enter
        If InStr("ABCD", Chr(KeyAscii)) = 0 Then
            SoloLETRAS = 0
        Else
            SoloLETRAS = KeyAscii
        End If ' teclas adicionales permitidas
        If KeyAscii = 8 Then SoloLETRAS = KeyAscii ' Backspace
        If KeyAscii = 13 Then SoloLETRAS = KeyAscii ' Enter
    End Function

   

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If rbtfem.Checked = True Then
            sexo = "F"
        ElseIf rbtmas.Checked = True Then
            sexo = "M"
        End If
        txtcodigo.Text = Microsoft.VisualBasic.Left(UCase(cboespecialidad.SelectedItem), 3) + sexo + NUDedad.Value.ToString + numero.ToString
    End Sub

    Private Sub cbocolegio_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbocolegio.SelectedIndexChanged
        Select Case cbocolegio.SelectedIndex
            Case 0
                txtpensionbase.Text = 160
            Case 1
                txtpensionbase.Text = 185
            Case 2
                txtpensionbase.Text = 220
        End Select
    End Sub

    Private Sub cboespecialidad_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboespecialidad.SelectedIndexChanged

        Select Case cboespecialidad.SelectedIndex
            Case 0
                especialidad = 80
            Case 1
                especialidad = 60
            Case 2
                especialidad = 50
        End Select
    End Sub

    Private Sub HSBcuotas_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HSBcuotas.Scroll
        txtcuota.Text = HSBcuotas.Value
    End Sub

    Private Sub txtseccion_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtseccion.KeyPress
        Dim KeyAscii As Short = CShort(Asc(e.KeyChar))
        KeyAscii = CShort(SoloLETRAS(KeyAscii))
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub btninscribir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btninscribir.Click
        txttotal.Text = (Val(txtpensionbase.Text) + especialidad) / Val(txtcuota.Text)
    End Sub
End Class

RETO5 – Principal



Public Class Principal
    Dim formfuente As New Formulario_Fuente
    Dim eje As New Ejecutables
    Dim fnumericas As New FuncionesNumericas
    Dim fcadena As New FuncionesCadena
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        tsslhora.Text = Date.Now().ToLongTimeString
    End Sub
    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim x As Long
        For x = ProgressBar1.Minimum To ProgressBar1.Maximum
            ProgressBar1.Value = x
        Next x
    End Sub
    Private Sub tsbffuente_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbffuente.Click
        If formfuente.IsDisposed Then
            formfuente = New Formulario_Fuente
            formfuente.MdiParent = Me
            formfuente.Show()
        Else : formfuente.MdiParent = Me
            formfuente.Show()
        End If
    End Sub
    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rsbfnumericas.Click
        If fnumericas.IsDisposed Then
            fnumericas = New FuncionesNumericas
            fnumericas.MdiParent = Me
            fnumericas.Show()
        Else : fnumericas.MdiParent = Me
            fnumericas.Show()
        End If
    End Sub
    Private Sub tsbfcadenas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbfcadenas.Click
        If fcadena.IsDisposed Then
            fcadena = New FuncionesCadena
            fcadena.MdiParent = Me
            fcadena.Show()
        Else : fcadena.MdiParent = Me
            fcadena.Show()
        End If
    End Sub
    Private Sub tsbexe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbexe.Click
        If eje.IsDisposed Then
            eje = New Ejecutables
            eje.MdiParent = Me
            eje.Show()
        Else : eje.MdiParent = Me
            eje.Show()
        End If
    End Sub
    Private Sub VerToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu2expandir.Click
        Me.WindowState = FormWindowState.Maximized
    End Sub

    Private Sub mnu2pequeño_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu2pequeño.Click
        Me.WindowState = FormWindowState.Normal
        Me.Size = New System.Drawing.Size(550, 200)
    End Sub

    Private Sub mnu2mediano_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu2mediano.Click
        Me.WindowState = FormWindowState.Normal
        Me.Size = New System.Drawing.Size(550, 500)
    End Sub

    Private Sub mnu2grande_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu2grande.Click
        Me.WindowState = FormWindowState.Normal
        Me.Size = New System.Drawing.Size(900, 800)
    End Sub

    Private Sub mnu1salir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu1salir.Click
        Application.Exit()
    End Sub
End Class

RETO5 – Funciones Numericas



Public Class FuncionesNumericas
    Private Sub btnmostrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmostrar.Click
        Dim numero As Double = txtnumero.Text
        Dim entero As Integer
        Dim decimalvar As Decimal
        Dim absoluto As Double
        Dim raiz As Double
        Dim signo As Integer
        entero = CInt(numero)
        txtentero.Text = entero
        decimalvar = CDec(numero)
        txtdecimal.Text = decimalvar
        absoluto = Math.Abs(numero)
        txtabsoluto.Text = absoluto
        raiz = Math.Sqrt(numero)
        txtraiz.Text = raiz
        signo = Math.Sign(numero)
        txtsigno.Text = signo
        txtoctal.Text = Oct(numero)
        txthexa.Text = Hex(numero)
    End Sub
    Private Sub Funciones_Numericas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtnumero.Text = 0
    End Sub

    Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnuevo.Click
        Dim ctl As Object
        For Each ctl In Me.Controls
            If TypeOf ctl Is TextBox Then
                ctl.Text = ""
            End If
        Next
    End Sub
    Private Sub btnsalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsalir.Click
        Dim salida As Integer = MsgBox("Desea Salir?",
        MsgBoxStyle.YesNo + 32, "Mensaje al usuario")
        If salida = 6 Then
            Me.Close()
        End If
    End Sub
End Class

RETO5 –Formato de Fuente



Public Class Formulario_Fuente
    Private Sub chkcursiva_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkcursiva.CheckedChanged
        If chkcursiva.Checked = True And chknegrita.Checked = False And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = True And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic + FontStyle.Bold)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = False And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic + FontStyle.Underline)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = True And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic + FontStyle.Bold + FontStyle.Underline)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = True And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Bold)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = False And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Underline)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = True And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Underline + FontStyle.Bold)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = False And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Regular)
        End If
    End Sub
    Private Sub chknegrita_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chknegrita.CheckedChanged
        If chkcursiva.Checked = False And chknegrita.Checked = True And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Bold)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = True And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Bold + FontStyle.Italic)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = True And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic + FontStyle.Bold + FontStyle.Underline)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = True And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Bold + FontStyle.Underline)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = False And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = False And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Underline)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = False And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Underline + FontStyle.Italic)
        Else
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Regular)
        End If
    End Sub
    Private Sub chksubrayada_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chksubrayada.CheckedChanged
        If chkcursiva.Checked = False And chknegrita.Checked = False And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Underline)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = True And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Underline + FontStyle.Bold)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = False And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Underline + FontStyle.Italic)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = False And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Regular)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = True And chksubrayada.Checked = True Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic + FontStyle.Bold + FontStyle.Underline)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = False And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic)
        ElseIf chkcursiva.Checked = False And chknegrita.Checked = True And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Bold)
        ElseIf chkcursiva.Checked = True And chknegrita.Checked = True And chksubrayada.Checked = False Then
            Me.lbltexto.Font = New System.Drawing.Font(lbltexto.Font, FontStyle.Italic + FontStyle.Bold)
        End If
    End Sub
    Private Sub cbocolor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbocolor.SelectedIndexChanged
        Select Case Me.cbocolor.SelectedIndex
            Case 0
                Me.lbltexto.ForeColor() = Color.Red
            Case 1
                Me.lbltexto.ForeColor() = Color.Blue
            Case 2
                Me.lbltexto.ForeColor() = Color.Green
        End Select
    End Sub
    Private Sub btnsalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsalir.Click
        Dim salida As Integer = MsgBox("Desea Salir?",
        MsgBoxStyle.YesNo + 32, "Mensaje al usuario")
        If salida = 6 Then
            Me.Close()
        End If
        Principal.tsbffuente.CheckState = CheckState.Unchecked
    End Sub
End Class