Hummm...

El otro día jugando con un Cubo Rubik me quise tomar el tiempo de cuanto me demoraba, para esto solía usar el cronómetro del celular... jejeje... pero en un momento quise tener uno en mi portatil... encontré en internet unos instaladores, pero me propuse hacer uno yo mismo... jejeje nada del otro mundo.

Lo primero fue como sumar y restar Horas... para eso encontré el tipo de datos TimeSpan que me sirvió notablemente para esto.

Puedes descargar el ejemplo completo desde aqui --->> Download   CLAVE ZIP: msmvps.com/jvargas

Para comenzar cree un formulario windows con un label, dos botones y un control timer.

El formulario es el siguiente:

El label se llama lblTiempo, el boton ">" se llama btnIniciarPausar, el botón "O" se llama btnDetener y el timer se llama tmrTiempo.

Ahi les adjunto los eventos correspondientes..

    Dim FechaInicio As DateTime, _
        TiempoActivo As TimeSpan

    Private Sub btnIniciarPausar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIniciarPausar.Click

        If btnIniciarPausar.Text = "||" Then
            'PAUSA
            btnIniciarPausar.Text = ">"
            tmrTiempo.Stop()
        Else
            'REINICIAR
            Dim FechaActiva As DateTime
            FechaActiva = lblTiempo.Text
            TiempoActivo = FechaActiva.TimeOfDay

            FechaInicio = Now
            btnDetener.Enabled = True
            btnIniciarPausar.Text = "||"
            tmrTiempo.Start()
        End If

    End Sub

    Private Sub btnDetener_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDetener.Click
        btnDetener.Enabled = False
        btnIniciarPausar.Text = ">"
        lblTiempo.Text = "00:00:00.000"
        tmrTiempo.Stop()
    End Sub

    Private Sub tmrTiempo_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrTiempo.Tick

        Dim Tiempo As TimeSpan

        Tiempo = Now.Subtract(FechaInicio).Duration
        Tiempo += TiempoActivo

        lblTiempo.Text = Microsoft.VisualBasic.Right("00" & Tiempo.Hours, 2) & ":" & _
                         Microsoft.VisualBasic.Right("00" & Tiempo.Minutes, 2) & ":" & _
                         Microsoft.VisualBasic.Right("00" & Tiempo.Seconds, 2) & "." & _
                         Microsoft.VisualBasic.Right("000" & Tiempo.Milliseconds, 3)

        Me.Refresh()

    End Sub


Espero les sirva este ejemplo en el uso de TimeSpan al igual que Datetime.

Saludos,

Jhonny Vargas P.

Gracias Gerardo.... adjunto el código para C#, por si algún otro usuario lo llegara a necesitar.

 

Para VB.NET http://msmvps.com/blogs/jvargas/pages/convertirnumeroletras.aspx

 

Gracias por tu aporte.

 

:)

 

 

using System;

using System.Collections.Generic;

using System.Text;

namespace Conversiones

{

   class Conv

   {

       public string enletras(string num)

       {

           string res, dec = "";

           Int64 entero;

           int decimales;

           double nro;

           try

           {

               nro = Convert.ToDouble(num);

           }

           catch

           {

               return "";

           }

           entero = Convert.ToInt64(Math.Truncate(nro));

           decimales = Convert.ToInt32(Math.Round((nro - entero) * 100, 2));

           if (decimales > 0)

           {

               dec = " CON " + decimales.ToString() + "/100";

           }

           res = toText(Convert.ToDouble(entero)) + dec;

           return res;

       }

       private string toText(double value)

       {

           string Num2Text = "";

           value = Math.Truncate(value);

           if (value == 0) Num2Text = "CERO";

           else if (value == 1) Num2Text = "UNO";

           else if (value == 2) Num2Text = "DOS";

           else if (value == 3) Num2Text = "TRES";

           else if (value == 4) Num2Text = "CUATRO";

           else if (value == 5) Num2Text = "CINCO";

           else if (value == 6) Num2Text = "SEIS";

           else if (value == 7) Num2Text = "SIETE";

           else if (value == 8) Num2Text = "OCHO";

           else if (value == 9) Num2Text = "NUEVE";

           else if (value == 10) Num2Text = "DIEZ";

           else if (value == 11) Num2Text = "ONCE";

           else if (value == 12) Num2Text = "DOCE";

           else if (value == 13) Num2Text = "TRECE";

           else if (value == 14) Num2Text = "CATORCE";

           else if (value == 15) Num2Text = "QUINCE";

           else if (value < 20) Num2Text = "DIECI" + toText(value - 10);

           else if (value == 20) Num2Text = "VEINTE";

           else if (value < 30) Num2Text = "VEINTI" + toText(value - 20);

           else if (value == 30) Num2Text = "TREINTA";

           else if (value == 40) Num2Text = "CUARENTA";

           else if (value == 50) Num2Text = "CINCUENTA";

           else if (value == 60) Num2Text = "SESENTA";

           else if (value == 70) Num2Text = "SETENTA";

           else if (value == 80) Num2Text = "OCHENTA";

           else if (value == 90) Num2Text = "NOVENTA";

           else if (value < 100) Num2Text = toText(Math.Truncate(value / 10) * 10) + " Y " + toText(value % 10);

           else if (value == 100) Num2Text = "CIEN";

           else if (value < 200) Num2Text = "CIENTO " + toText(value - 100);

           else if ((value == 200) || (value == 300) || (value == 400) || (value == 600) || (value == 800)) Num2Text = toText(Math.Truncate(value / 100)) + "CIENTOS";

           else if (value == 500) Num2Text = "QUINIENTOS";

           else if (value == 700) Num2Text = "SETECIENTOS";

           else if (value == 900) Num2Text = "NOVECIENTOS";

           else if (value < 1000) Num2Text = toText(Math.Truncate(value / 100) * 100) + " " + toText(value % 100);

           else if (value == 1000) Num2Text = "MIL";

           else if (value < 2000) Num2Text = "MIL " + toText(value % 1000);

           else if (value < 1000000)

           {

               Num2Text = toText(Math.Truncate(value / 1000)) + " MIL";

               if ((value % 1000) > 0) Num2Text = Num2Text + " " + toText(value % 1000);

           }

           else if (value == 1000000) Num2Text = "UN MILLON";

           else if (value < 2000000) Num2Text = "UN MILLON " + toText(value % 1000000);

           else if (value < 1000000000000)

           {

               Num2Text = toText(Math.Truncate(value / 1000000)) + " MILLONES ";

               if ((value - Math.Truncate(value / 1000000) * 1000000) > 0) Num2Text = Num2Text + " " + toText(value - Math.Truncate(value / 1000000) * 1000000);

           }

           else if (value == 1000000000000) Num2Text = "UN BILLON";

           else if (value < 2000000000000) Num2Text = "UN BILLON " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000);

           else

           {

               Num2Text = toText(Math.Truncate(value / 1000000000000)) + " BILLONES";

               if ((value - Math.Truncate(value / 1000000000000) * 1000000000000) > 0) Num2Text = Num2Text + " " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000);

           }

           return Num2Text;

       }

   }

}

Posted by jvargas | 2 comment(s)
Filed under: , ,

http://msmvps.com/blogs/jvargas/pages/ejecutarDTS.aspx

Posted by jvargas | 1 comment(s)
Filed under:

http://msmvps.com/blogs/jvargas/pages/convertirnumeroletras.aspx

Posted by jvargas | 7 comment(s)

http://msmvps.com/blogs/jvargas/pages/ejecutarconsultasSQL.aspx

http://msmvps.com/blogs/jvargas/pages/impersonar.aspx

Posted by jvargas | with no comments

http://msmvps.com/blogs/jvargas/pages/utilizarservicioweb.aspx

Posted by jvargas | with no comments
Filed under: ,

http://msmvps.com/blogs/jvargas/pages/97139.aspx

Posted by jvargas | 1 comment(s)

http://msmvps.com/blogs/jvargas/pages/binariosaspnet.aspx

Posted by jvargas | with no comments

http://msmvps.com/blogs/jvargas/pages/10304.aspx

Posted by jvargas | with no comments
Filed under:

http://msmvps.com/blogs/jvargas/pages/10303.aspx

Posted by jvargas | with no comments
Filed under:

http://msmvps.com/blogs/jvargas/pages/ConvertirTif.aspx

Posted by jvargas | with no comments

http://msmvps.com/blogs/jvargas/pages/10302.aspx

Posted by jvargas | with no comments
Filed under:

http://msmvps.com/blogs/jvargas/pages/10291.aspx

Posted by jvargas | with no comments
Filed under:
La pregunta parece bastante simple... utilicemos un DateDiff, pero DateDiff solo entrega la Cantidad de meses entre ese Rango y en forma separada te entrega la cantidad de días entre ese rango de fechas. Pero no devuelve ambas al mismo tiempo. Por ejemplo...
Posted by jvargas | 2 comment(s)
Ayer necesitaba convertir un multi tiff (multiples imágenes en un solo archivo) a varios JPGs o GIFs... ufff un caos, ya que directamente al cargar un Multitiff y realizar la conversión a jpg o gif, solo me tomaba la primera imagen del multi tiff... buscando por internet (san google) encontré la información en varias partes, por eso mismo cree una rutina en donde saqué un poco de código de un lado y de otros lados.
 
Por si alguien en algún momento lo llega a utilizar consuntar aqui.
 
Antiguamente para Visual Basic 6.0 (y gracias a mi jefe) utilizaba la herramienta Lead Tools, en realidad solo la utilicé para visualizar imagenes multi tiff  y hacer un par de cosas, transformaciones, etc... mi jefe usaba bastante esta herramienta, la cual llegaba hasta el reconocimiento de letras y números, bastante buena... ahora con .NET solo se requieren un par de elementos y listo... ya estaba pensando en utilizar LeadTools en .NET para convertir el tif a gif, me ahorré de instalar un monton de librerías.
 
Saludos,
Jhonny Vargas P.
Posted by jvargas | 3 comment(s)
Filed under:
Desde hace un tiempo que he estado leyendo algunas historias que ha escrito Isaac Asimov, bastante buenas muy futuristas, de robótica... genial 100% recomendable, aparte que son entretenidas y del tiempo en que fueron escritas te hacen pensar la mente que tenía este escritor.
 
Bueno que tiene que ver multivac con encarta, antes que nada Multivac para Asimov o para las historias que escribió, era una gran computadora que respondía todo lo que cualquier persona quisiera saber, desde lo más esencial hasta lo más complejo que uno se pueda imaginar, Multivac era quien juzgaba a las personas por los crímenes que cometía, ya que poseía un gran intelecto y una objetividad mejor que un juez humano.
 
Insisto que tiene que ver multivac con encarta XD, hace unas semanas me enteré de la existencia de un correo messenger llamado encarta@conversagent.com, lo agregué y me encontré con que me respondía todo lo que yo escribía... de lo más esencial hasta lo más complejo, obviamente Encarta no posee la habilidad que alguna vez soñó Asimov, pero sin duda se asemejan bastante.
 
Los invito a incorporar y jugar un poco con este gran invento encarta@conversagent.com
 
Saludos,
Jhonny Vargas P.
Santiago de Chile
 
Posted by jvargas | 4 comment(s)
Filed under:
Uffff, hace tiempo que no ingresaba por estos lados... ahora volveré a comenzar escribiendo algunos apuntes y códigos que espero les sean utiles..

Acabo de crear una nueva categoría llamada ASP.NET, subi una nueva versión para enviar archivo binarios al browser en .NET..

Más Informacion de ASP.NET

Saludos,
Jhonny Vargas P.
Santiago de Chile
Posted by jvargas | with no comments
Filed under:

Acabo de crear algunos artículos relacionados con ASP tradicional, son algunas cosas básicas espero ir poblando de apoco este sector.

Aquí más información

Saludos,
Jhonny Vargas P.
Santiago de Chile.
Posted by jvargas | with no comments
Filed under:

Hola a todos,

Por supuesto me voy a presentar, mi nombre es Jhonny Vargas P. y vivo en Santiago de Chile...

Quiero agradecer a Susan Bradley de http://www.msmvps.com por esta gran idea...

Espero pronto colocar algunos artículos e información relacionada con .NET

 

Saludos!.

 

Posted by jvargas | 2 comment(s)
Filed under: