lunes, mayo 29, 2017

Convertir Número a Letras en VB

Más de uno nos hemos roto en algún momento de nuestra vida la cabeza por querer desarrollar una rutina que nos permita convertir números a letras, es por ello que decidí compartir con todos uds. el presente artículo.
Consiste en una aplicación desarrollada en VB.Net apoyada con un módulo que recibe como parametro el valor ingresado y lo convierte en letras dependiendo si es positivo o negativo.
A continuación lo detallo en forma más específica:



Public Class FrmNumeroaletra
    Inherits System.Windows.Forms.Form
    '****************************************
    'Desarrollado por: Pedro Alex Taya Yactayo
    'Email: alextaya@hotmail.com
    'Web: http://es.geocities.com/wiseman_alextaya
    '     http://groups.msn.com/mugcanete
    '****************************************

#Region " Código generado por el Diseñador de Windows Forms "

    Public Sub New()
        MyBase.New()

        'El Diseñador de Windows Forms requiere esta llamada.
        InitializeComponent()

        'Agregar cualquier inicialización después de la llamada a InitializeComponent()

    End Sub

    'Form reemplaza a Dispose para limpiar la lista de componentes.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Requerido por el Diseñador de Windows Forms
    Private components As System.ComponentModel.IContainer

    'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
    'Puede modificarse utilizando el Diseñador de Windows Forms. 
    'No lo modifique con el editor de código.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents CmdConvertir As System.Windows.Forms.Button
    Friend WithEvents TxtNumero As System.Windows.Forms.TextBox
    Friend WithEvents TxtLetra As System.Windows.Forms.TextBox
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents credito As System.Windows.Forms.Label
     Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FrmNumeroaletra))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.CmdConvertir = New System.Windows.Forms.Button
        Me.TxtNumero = New System.Windows.Forms.TextBox
        Me.TxtLetra = New System.Windows.Forms.TextBox
        Me.credito = New System.Windows.Forms.Label
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.Navy
        Me.Label1.Location = New System.Drawing.Point(8, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(38, 18)
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "Valor"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.Color.FromArgb(CType(64, Byte), CType(0, Byte), CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(8, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(66, 18)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "En Letras"
        '
        'CmdConvertir
        '
        Me.CmdConvertir.BackColor = System.Drawing.Color.Navy
        Me.CmdConvertir.Cursor = System.Windows.Forms.Cursors.Hand
        Me.CmdConvertir.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.CmdConvertir.ForeColor = System.Drawing.Color.White
        Me.CmdConvertir.Location = New System.Drawing.Point(232, 8)
        Me.CmdConvertir.Name = "CmdConvertir"
        Me.CmdConvertir.TabIndex = 1
        Me.CmdConvertir.Text = "&Convertir"
        '
        'TxtNumero
        '
        Me.TxtNumero.Location = New System.Drawing.Point(88, 8)
        Me.TxtNumero.Name = "TxtNumero"
        Me.TxtNumero.Size = New System.Drawing.Size(128, 20)
        Me.TxtNumero.TabIndex = 0
        Me.TxtNumero.Text = ""
        '
        'TxtLetra
        '
        Me.TxtLetra.Location = New System.Drawing.Point(88, 40)
        Me.TxtLetra.Name = "TxtLetra"
        Me.TxtLetra.ReadOnly = True
        Me.TxtLetra.Size = New System.Drawing.Size(456, 20)
        Me.TxtLetra.TabIndex = 2
        Me.TxtLetra.Text = ""
        '
        'credito
        '
        Me.credito.Font = New System.Drawing.Font("Microsoft Sans Serif", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.credito.ForeColor = System.Drawing.Color.Green
        Me.credito.Location = New System.Drawing.Point(312, 64)
        Me.credito.Name = "credito"
        Me.credito.Size = New System.Drawing.Size(232, 40)
        Me.credito.TabIndex = 5
        Me.credito.Text = "Desarrollado por: Pedro Alex Taya Yactayo alextaya@hotmail.com  http:"//es.geociti" & _
        "es.com/wiseman_alextaya"
        Me.credito.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 500
        '
        'FrmNumeroaletra
        '
        Me.AcceptButton = Me.CmdConvertir
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(550, 100)
        Me.Controls.Add(Me.credito)
        Me.Controls.Add(Me.TxtLetra)
        Me.Controls.Add(Me.TxtNumero)
        Me.Controls.Add(Me.CmdConvertir)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "FrmNumeroaletra"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Convertir Número a Letra"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub CmdConvertir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdConvertir.Click
        TxtLetra.Text = ""
        If IsNumeric(TxtNumero.Text) Then
            TxtLetra.Text = Letras(TxtNumero.Text)
        Else
            MessageBox.Show("Ingrese por favor números", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        TxtNumero.Focus()
        TxtNumero.SelectionStart = 0
        TxtNumero.SelectionLength = TxtNumero.ToString.Length
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static cColor As String
        If cColor = "" Then
            credito.ForeColor = System.Drawing.Color.Blue
            cColor = "a"
        Else
            credito.ForeColor = System.Drawing.Color.Green
            cColor = ""
        End If
    End Sub
End Class
Luego tenemos que crear el siguiente Módulo:
Module aletras
    '****************************************
    'Desarrollado por: Pedro Alex Taya Yactayo
    'Email: alextaya@hotmail.com
    'Web: http://es.geocities.com/wiseman_alextaya
    '     http://groups.msn.com/mugcanete
    '****************************************

    Public Function Letras(ByVal numero As String) As String
        '********Declara variables de tipo cadena************
        Dim palabras, entero, dec, flag As String

        '********Declara variables de tipo entero***********
        Dim num, x, y As Integer

        flag = "N"

        '**********Número Negativo***********
        If Mid(numero, 1, 1) = "-" Then
            numero = Mid(numero, 2, numero.ToString.Length - 1).ToString
            palabras = "menos "
        End If

        '**********Si tiene ceros a la izquierda*************
        For x = 1 To numero.ToString.Length
            If Mid(numero, 1, 1) = "0" Then
                numero = Trim(Mid(numero, 2, numero.ToString.Length).ToString)
                If Trim(numero.ToString.Length) = 0 Then palabras = ""
            Else
                Exit For
            End If
        Next

        '*********Dividir parte entera y decimal************
        For y = 1 To Len(numero)
            If Mid(numero, y, 1) = "." Then
                flag = "S"
            Else
                If flag = "N" Then
                    entero = entero + Mid(numero, y, 1)
                Else
                    dec = dec + Mid(numero, y, 1)
                End If
            End If
        Next y

        If Len(dec) = 1 Then dec = dec & "0"

        '**********proceso de conversión***********
        flag = "N"

        If Val(numero) <= 999999999 Then
            For y = Len(entero) To 1 Step -1
                num = Len(entero) - (y - 1)
                Select Case y
                    Case 3, 6, 9
                        '**********Asigna las palabras para las centenas***********
                        Select Case Mid(entero, num, 1)
                            Case "1"
                                If Mid(entero, num + 1, 1) = "0" And Mid(entero, num + 2, 1) = "0" Then
                                    palabras = palabras & "cien "
                                Else
                                    palabras = palabras & "ciento "
                                End If
                            Case "2"
                                palabras = palabras & "doscientos "
                            Case "3"
                                palabras = palabras & "trescientos "
                            Case "4"
                                palabras = palabras & "cuatrocientos "
                            Case "5"
                                palabras = palabras & "quinientos "
                            Case "6"
                                palabras = palabras & "seiscientos "
                            Case "7"
                                palabras = palabras & "setecientos "
                            Case "8"
                                palabras = palabras & "ochocientos "
                            Case "9"
                                palabras = palabras & "novecientos "
                        End Select
                    Case 2, 5, 8
                        '*********Asigna las palabras para las decenas************
                        Select Case Mid(entero, num, 1)
                            Case "1"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    flag = "S"
                                    palabras = palabras & "diez "
                                End If
                                If Mid(entero, num + 1, 1) = "1" Then
                                    flag = "S"
                                    palabras = palabras & "once "
                                End If
                                If Mid(entero, num + 1, 1) = "2" Then
                                    flag = "S"
                                    palabras = palabras & "doce "
                                End If
                                If Mid(entero, num + 1, 1) = "3" Then
                                    flag = "S"
                                    palabras = palabras & "trece "
                                End If
                                If Mid(entero, num + 1, 1) = "4" Then
                                    flag = "S"
                                    palabras = palabras & "catorce "
                                End If
                                If Mid(entero, num + 1, 1) = "5" Then
                                    flag = "S"
                                    palabras = palabras & "quince "
                                End If
                                If Mid(entero, num + 1, 1) > "5" Then
                                    flag = "N"
                                    palabras = palabras & "dieci"
                                End If
                            Case "2"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    palabras = palabras & "veinte "
                                    flag = "S"
                                Else
                                    palabras = palabras & "veinti"
                                    flag = "N"
                                End If
                            Case "3"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    palabras = palabras & "treinta "
                                    flag = "S"
                                Else
                                    palabras = palabras & "treinta y "
                                    flag = "N"
                                End If
                            Case "4"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    palabras = palabras & "cuarenta "
                                    flag = "S"
                                Else
                                    palabras = palabras & "cuarenta y "
                                    flag = "N"
                                End If
                            Case "5"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    palabras = palabras & "cincuenta "
                                    flag = "S"
                                Else
                                    palabras = palabras & "cincuenta y "
                                    flag = "N"
                                End If
                            Case "6"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    palabras = palabras & "sesenta "
                                    flag = "S"
                                Else
                                    palabras = palabras & "sesenta y "
                                    flag = "N"
                                End If
                            Case "7"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    palabras = palabras & "setenta "
                                    flag = "S"
                                Else
                                    palabras = palabras & "setenta y "
                                    flag = "N"
                                End If
                            Case "8"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    palabras = palabras & "ochenta "
                                    flag = "S"
                                Else
                                    palabras = palabras & "ochenta y "
                                    flag = "N"
                                End If
                            Case "9"
                                If Mid(entero, num + 1, 1) = "0" Then
                                    palabras = palabras & "noventa "
                                    flag = "S"
                                Else
                                    palabras = palabras & "noventa y "
                                    flag = "N"
                                End If
                        End Select
                    Case 1, 4, 7
                        '*********Asigna las palabras para las unidades*********
                        Select Case Mid(entero, num, 1)
                            Case "1"
                                If flag = "N" Then
                                    If y = 1 Then
                                        palabras = palabras & "uno "
                                    Else
                                        palabras = palabras & "un "
                                    End If
                                End If
                            Case "2"
                                If flag = "N" Then palabras = palabras & "dos "
                            Case "3"
                                If flag = "N" Then palabras = palabras & "tres "
                            Case "4"
                                If flag = "N" Then palabras = palabras & "cuatro "
                            Case "5"
                                If flag = "N" Then palabras = palabras & "cinco "
                            Case "6"
                                If flag = "N" Then palabras = palabras & "seis "
                            Case "7"
                                If flag = "N" Then palabras = palabras & "siete "
                            Case "8"
                                If flag = "N" Then palabras = palabras & "ocho "
                            Case "9"
                                If flag = "N" Then palabras = palabras & "nueve "
                        End Select
                End Select

                '***********Asigna la palabra mil***************
                If y = 4 Then
                    If Mid(entero, 6, 1) <> "0" Or Mid(entero, 5, 1) <> "0" Or Mid(entero, 4, 1) <> "0" Or _
                    (Mid(entero, 6, 1) = "0" And Mid(entero, 5, 1) = "0" And Mid(entero, 4, 1) = "0" And _
                    Len(entero) <= 6) Then palabras = palabras & "mil "
                End If

                '**********Asigna la palabra millón*************
                If y = 7 Then
                    If Len(entero) = 7 And Mid(entero, 1, 1) = "1" Then
                        palabras = palabras & "millón "
                    Else
                        palabras = palabras & "millones "
                    End If
                End If
            Next y

            '**********Une la parte entera y la parte decimal*************
            If dec <> "" Then
                Letras = palabras & "con " & dec
            Else
                Letras = palabras
            End If
        Else
            Letras = ""
        End If
    End Function
End Module
Espero les sirva de algo esta rutina, si es así por favor colabora conmigo votando por este artículo.
Hasta la próxima oportunidad.....:=)

Intervalo de Tiempo

Introducción
Casi siempre tenemos problemas cuando queremos trabajar ya sea con fechas u horas, creo yo que más de uno, nos hemos roto la cabeza tratando de solucionar este tipo de inconveniente, por ello he tratado de desarrollar este pequeño pero ilustrativo artículo donde muestro como podemos trabajar con estos tipos de datos en Visual Basic .Net.
Primero vamos recordar que dentro de SYSTEM (Espacio de Nombres) podemos localizar una serie de miembros que pueden ser Clases, Interfaces, Estructuras, Delegados y Enumeraciones que nos permiten realizar una serie de tareas, pero de quien nos vamos a centrar en este artículo es TIMESPAN (Estructura).
TimeSpan (Estructura)
Nos permite representar un intervalo de tiempo tomando como base una Fecha/Hora Inicial y una Fecha/Hora Final, devuelve la cantidad de Días, Horas, Minutos, Segundos, etc., transcurridos entre este intervalo de tiempo.
Hay que recordar la siguiente jerarquía.
System  
 System.Object 
  System.ValueType 
   System.TimeSpan
Estos son los requisitos para poder utilizarlo:
Espacio de Nombres: System
Plataformas: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional Edition, Familia de Windows Server 2003, .NET Compact Framework - Windows CE .NET
Ensamblado: Mscorlib (en Mscorlib.dll)
....Bueno ahora vamos ha realizar lo que más nos agrada, que es un ejemplo de como hallar el intervalo de tiempo transcurrido entre dos fechas/horas:
Primero; realizamos lo que conocemos como Tiempo de Diseño:
 Interfaz: Debemos de crear un formulario con los siguientes controles.

 ....Ahora vamos a ver como debe de quedar el Explorador de Soluciones:

Segundo; ahora vamos a tratar de describir lo que llamamos el Tiempo de Ejecución:
Public Class FrmInterDateTime
    Inherits System.Windows.Forms.Form
    Public flagestado As Boolean = False

#Region " Código generado por el Diseñador de Windows Forms "

    Public Sub New()
        MyBase.New()

        'El Diseñador de Windows Forms requiere esta llamada.
        InitializeComponent()

        'Agregar cualquier inicialización después de la llamada a InitializeComponent()

    End Sub

    'Form reemplaza a Dispose para limpiar la lista de componentes.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Requerido por el Diseñador de Windows Forms
    Private components As System.ComponentModel.IContainer

    'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
    'Puede modificarse utilizando el Diseñador de Windows Forms. 
    'No lo modifique con el editor de código.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents TxtDTInicio As System.Windows.Forms.TextBox
    Friend WithEvents TxtDtFinal As System.Windows.Forms.TextBox
    Friend WithEvents TxtDia As System.Windows.Forms.TextBox
    Friend WithEvents TxtHra As System.Windows.Forms.TextBox
    Friend WithEvents TxtMin As System.Windows.Forms.TextBox
    Friend WithEvents TxtSeg As System.Windows.Forms.TextBox
    Friend WithEvents TimerTitulo As System.Windows.Forms.Timer
    Friend WithEvents TimerOpacity As System.Windows.Forms.Timer
    Friend WithEvents TimerOpacity2 As System.Windows.Forms.Timer
    Friend WithEvents CmdIntervalo As System.Windows.Forms.Button
     Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FrmInterDateTime))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.TxtDTInicio = New System.Windows.Forms.TextBox
        Me.TxtDtFinal = New System.Windows.Forms.TextBox
        Me.CmdIntervalo = New System.Windows.Forms.Button
        Me.TxtDia = New System.Windows.Forms.TextBox
        Me.TxtHra = New System.Windows.Forms.TextBox
        Me.TxtMin = New System.Windows.Forms.TextBox
        Me.TxtSeg = New System.Windows.Forms.TextBox
        Me.TimerTitulo = New System.Windows.Forms.Timer(Me.components)
        Me.TimerOpacity = New System.Windows.Forms.Timer(Me.components)
        Me.TimerOpacity2 = New System.Windows.Forms.Timer(Me.components)
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 16.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.RoyalBlue
        Me.Label1.Location = New System.Drawing.Point(63, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(210, 28)
        Me.Label1.TabIndex = 8
        Me.Label1.Text = "Intervalo de Tiempo"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.ForeColor = System.Drawing.Color.Crimson
        Me.Label2.Location = New System.Drawing.Point(16, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Fecha/Hora Inicial"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.ForeColor = System.Drawing.Color.Crimson
        Me.Label3.Location = New System.Drawing.Point(176, 48)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(91, 16)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "Fecha/Hora Final"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.ForeColor = System.Drawing.Color.Teal
        Me.Label4.Location = New System.Drawing.Point(61, 96)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(31, 16)
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "Días:"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.ForeColor = System.Drawing.Color.Teal
        Me.Label5.Location = New System.Drawing.Point(53, 120)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(39, 16)
        Me.Label5.TabIndex = 4
        Me.Label5.Text = "Horas:"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.ForeColor = System.Drawing.Color.Teal
        Me.Label6.Location = New System.Drawing.Point(43, 144)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(49, 16)
        Me.Label6.TabIndex = 5
        Me.Label6.Text = "Minutos:"
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label7.ForeColor = System.Drawing.Color.Teal
        Me.Label7.Location = New System.Drawing.Point(32, 168)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(60, 16)
        Me.Label7.TabIndex = 6
        Me.Label7.Text = "Segundos:"
        '
        'TxtDTInicio
        '
        Me.TxtDTInicio.Location = New System.Drawing.Point(16, 64)
        Me.TxtDTInicio.Name = "TxtDTInicio"
        Me.TxtDTInicio.Size = New System.Drawing.Size(144, 20)
        Me.TxtDTInicio.TabIndex = 1
        Me.TxtDTInicio.Text = "08/07/2004 08:00:00 a.m."
        '
        'TxtDtFinal
        '
        Me.TxtDtFinal.Location = New System.Drawing.Point(176, 64)
        Me.TxtDtFinal.Name = "TxtDtFinal"
        Me.TxtDtFinal.Size = New System.Drawing.Size(144, 20)
        Me.TxtDtFinal.TabIndex = 2
        Me.TxtDtFinal.Text = ""
        '
        'CmdIntervalo
        '
        Me.CmdIntervalo.ForeColor = System.Drawing.Color.Navy
        Me.CmdIntervalo.Image = CType(resources.GetObject("CmdIntervalo.Image"), System.Drawing.Image)
        Me.CmdIntervalo.ImageAlign = System.Drawing.ContentAlignment.TopCenter
        Me.CmdIntervalo.Location = New System.Drawing.Point(208, 112)
        Me.CmdIntervalo.Name = "CmdIntervalo"
        Me.CmdIntervalo.Size = New System.Drawing.Size(72, 56)
        Me.CmdIntervalo.TabIndex = 0
        Me.CmdIntervalo.Text = "&Hallar Intervalo"
        Me.CmdIntervalo.TextAlign = System.Drawing.ContentAlignment.BottomCenter
        '
        'TxtDia
        '
        Me.TxtDia.Location = New System.Drawing.Point(96, 96)
        Me.TxtDia.Name = "TxtDia"
        Me.TxtDia.ReadOnly = True
        Me.TxtDia.Size = New System.Drawing.Size(60, 20)
        Me.TxtDia.TabIndex = 9
        Me.TxtDia.Text = ""
        Me.TxtDia.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'TxtHra
        '
        Me.TxtHra.Location = New System.Drawing.Point(96, 120)
        Me.TxtHra.Name = "TxtHra"
        Me.TxtHra.ReadOnly = True
        Me.TxtHra.Size = New System.Drawing.Size(60, 20)
        Me.TxtHra.TabIndex = 10
        Me.TxtHra.Text = ""
        Me.TxtHra.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'TxtMin
        '
        Me.TxtMin.Location = New System.Drawing.Point(96, 144)
        Me.TxtMin.Name = "TxtMin"
        Me.TxtMin.ReadOnly = True
        Me.TxtMin.Size = New System.Drawing.Size(60, 20)
        Me.TxtMin.TabIndex = 11
        Me.TxtMin.Text = ""
        Me.TxtMin.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'TxtSeg
        '
        Me.TxtSeg.Location = New System.Drawing.Point(96, 168)
        Me.TxtSeg.Name = "TxtSeg"
        Me.TxtSeg.ReadOnly = True
        Me.TxtSeg.Size = New System.Drawing.Size(60, 20)
        Me.TxtSeg.TabIndex = 12
        Me.TxtSeg.Text = ""
        Me.TxtSeg.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'TimerTitulo
        '
        Me.TimerTitulo.Enabled = True
        Me.TimerTitulo.Interval = 300
        '
        'TimerOpacity
        '
        '
        'TimerOpacity2
        '
        Me.TimerOpacity2.Enabled = True
        '
        'FrmInterDateTime
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(336, 200)
        Me.Controls.Add(Me.TxtSeg)
        Me.Controls.Add(Me.TxtMin)
        Me.Controls.Add(Me.TxtHra)
        Me.Controls.Add(Me.TxtDia)
        Me.Controls.Add(Me.CmdIntervalo)
        Me.Controls.Add(Me.TxtDtFinal)
        Me.Controls.Add(Me.TxtDTInicio)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "FrmInterDateTime"
        Me.Opacity = 0
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Intervalo de Tiempo - alextaya@hotmail.com                          "
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub FrmInterDateTime_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TxtDtFinal.Text = Now
    End Sub

    Private Sub VerInterDateTime(ByVal TSpan As TimeSpan)
        TxtDia.Text = TSpan.Days.ToString
        TxtHra.Text = TSpan.Hours.ToString
        TxtMin.Text = TSpan.Minutes.ToString
        TxtSeg.Text = TSpan.Seconds.ToString
    End Sub

    Private Sub TimerTitulo_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerTitulo.Tick
        Me.Text = Microsoft.VisualBasic.Right(Me.Text, (Len(Me.Text) - 1)) + Microsoft.VisualBasic.Left(Me.Text, 1)
    End Sub

    Private Sub TimerOpacity_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerOpacity.Tick
        Me.Opacity -= 0.05
        If Me.Opacity = 0 Then
            flagestado = True
            Me.Close()
        End If
    End Sub

    Private Sub FrmInterDateTime_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If flagestado = False Then
            e.Cancel = True
            Me.TimerOpacity.Enabled = True
        End If
    End Sub

    Private Sub TimerOpacity2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerOpacity2.Tick
        Me.Opacity += 0.05
        If Me.Opacity = 1 Then
            Me.TimerOpacity2.Enabled = False
        End If
    End Sub

    Private Sub CmdIntervalo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdIntervalo.Click
        Dim TSpan As TimeSpan
        Dim DTInicio As DateTime
        Dim DtFinal As DateTime

        DTInicio = DateTime.Parse(TxtDTInicio.Text)
        DtFinal = DateTime.Parse(TxtDtFinal.Text)

        TSpan = DtFinal.Subtract(DTInicio).Duration
        VerInterDateTime(TSpan)
    End Sub
End Class

Ahora simplemente nos queda ejecutar la solución para ver que todo este bien, espero que funcione
sin ningún problema jeje ;).

Espero poder publicar un artículo similar pero utilizando C# en los próximos días.
Me despido esperando haber contribuido con un granito de arena en este fascinante mundo .Net. Nos vemos líneas de código más adelante.

Microsoft VBA (Visual Basic for Applications)

Microsoft VBA (Visual Basic for Applications) es el lenguaje de macros de Microsoft Visual Basic que se utiliza para programar aplicaciones Windows y que se incluye en varias aplicaciones Microsoft. VBA permite a usuarios y programadores ampliar la funcionalidad de programas de la suite Microsoft Office. Visual Basic para Aplicaciones es un subconjunto casi completo de Visual Basic 5.0 y 6.0.


Descargar demo ==> https://1drv.ms/p/s!AmaJ_dzHcGkhhMZUkYyCsJXTlsgc4Q
Saludos.

¿Qué es un Algoritmo?

Más información ==>  https://m.facebook.com/story.php?story_fbid=779713015547334&id=332220556963251