martes, 15 de junio de 2010

Codigo Clase 16/06/2010

Public Class Form1
    'Declaro a nivel global los vectores para:
    'nombre, tipo iva, y la CUIT
    Dim Nom() As String
    Dim tipoiva() As String
    Dim cuit() As Double
    '''''''''''''''''''''''''''''''''''''''''''
 
    Sub LimpiarUnTexBox(ByRef txt As TextBox)
        txt.Text = ""
    End Sub
    Function AgregarElementosAlVector() As Boolean
        Dim cantidadDeElementos As Integer
        Dim banderaEsElPrimerElemento As Boolean = False
        'verifico si el objeto ha sido instanciado
        If Nom Is Nothing Then 'el vector no tiene ningún elemento
            ReDim Nom(0)
            ReDim cuit(0)
            ReDim tipoiva(0)
            banderaEsElPrimerElemento = True
        End If
        For indiceDelVector As Integer = 0 To Nom.Length - 1
            If Nom(indiceDelVector) = Me.Texto.Text Then
                MsgBox("El nombre ingresado ya existe")
                Return False
            End If
        Next
        'Acordarse de la concatenación:
        'Dim s as string
        'Dim j as string
        'Dim a As string
        'Dim b AS string
        'j="juan"
        'a="alberto"
        'b="Badía"
        's = j &  a & b
        If banderaEsElPrimerElemento Then
            Nom(0) = Me.Texto.Text
        Else
            cantidadDeElementos = Nom.Length
            ReDim Preserve Nom(cantidadDeElementos)
            Nom(cantidadDeElementos) = Texto.Text
        End If

    End Function

    Private Sub Combo1_SelectedIndexChanged(ByVal sender As System.Object, _
                                            ByVal e As System.EventArgs) Handles Combo1.SelectedIndexChanged
        If Combo1.Text = "Consumidor Final" Then
            LimpiarUnTexBox(Text1)
            Text1.Enabled = False
            Text1.BackColor = Color.Silver
            LimpiarUnTexBox(Text2)
            Text2.Text = ""
            Text2.Enabled = False
            Text2.BackColor = Color.Silver
            LimpiarUnTexBox(Text3)
            Text3.Text = ""
            Text3.Enabled = False
            Text3.BackColor = Color.Silver
        Else
            Text1.Enabled = True
            Text1.BackColor = Color.White
            Text2.Enabled = True
            Text2.BackColor = Color.White
            Text3.Enabled = True
            Text3.BackColor = Color.White
        End If
    End Sub
 
 
 
    Private Sub Text1_KeyPress(ByVal sender As System.Object, _
                               ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                               Handles Text1.KeyPress
        If Asc(e.KeyChar) = 8 Then 'controlo si ha ingresado el BackSpace (codigo Ascii N°8)
            Exit Sub
        End If
        Dim auxIntAscciCode = Asc(e.KeyChar)
        If Not (auxIntAscciCode >= CInt(System.Windows.Forms.Keys.D0) _
                AndAlso auxIntAscciCode <= CInt(System.Windows.Forms.Keys.D9)) Then
            'cambio el valor de la letra, por vacío
            e.KeyChar = ""
        End If
    End Sub
    'Item 5 del ejercicio (al presionar Enter en "Texto"...)
    Private Sub Texto_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Texto.KeyPress
        If Asc(e.KeyChar) = 13 Then
            Combo1.Focus()
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Validar
        If String.IsNullOrEmpty(Texto.Text.Trim) Then
            MsgBox("Debe Ingresar un nombre")
            Texto.Focus()
            Exit Sub
        End If
        If Combo1.Text <> "Consumidor Final" Then
            'Verifico que haya ingresado el IVA
            If String.IsNullOrEmpty(Text1.Text.Trim) Then
                MsgBox("Debe Ingresar El primer dígito de la CUIL")
                Text1.Focus()
                Exit Sub
            End If
            If String.IsNullOrEmpty(Text2.Text.Trim) Then
                MsgBox("Debe Ingresar El segundo dígito de la CUIL")
                Text2.Focus()
                Exit Sub
            End If

            If String.IsNullOrEmpty(Text3.Text.Trim) Then
                MsgBox("Debe Ingresar El Tercer dígito de la CUIL")
                Text3.Focus()
                Exit Sub
            End If
        End If
        Dim retornoAgregar As Boolean = True
        retornoAgregar = AgregarElementosAlVector()
    End Sub
End Class

 

No hay comentarios:

Publicar un comentario