[SOLUCIONADO] Calcular el tiempo restante

(1/1)

Eleкtro:
Lo del tiempo transcurrido lo tengo manejado ya, pero para mostrar el tiempo restante me estoy haciendo un lío...

Código
   Dim time_out as integer = 60000 ' 'Milisegundos
 
   Dim StartTime As DateTime ' Tiempo inicio
   Dim EndTime As DateTime ' Tiempo final
 
   Dim ElapsedTime As TimeSpan ' Tiempo transcurrido
   Dim RemainingTime As TimeSpan ' Tiempo restante

He conseguido mostrar el tiempo restante pero de una manera extraña, el problema es que, aparte de que los valores se muestran negativos, el valor de la hora y el minutero deberían ser "00"... ya que sólo estoy intentando medir el tiempo restante de una operación de "10000" MS (10 segs)

Output:


Este es el code que uso, ¿Como lo arreglo?
Código
#Region " Elapsed Time Function "
 
   Public Function Print_Elapsed_Time()
       If StartTime.ToString = "01/01/0001 0:00:00" Then
           StartTime = Now
           StartTime = StartTime.AddSeconds(-1)
       End If
       ElapsedTime = Now().Subtract(StartTime)
       Return String.Format("{0:00}:{1:00}:{2:00}", CInt(Math.Floor(ElapsedTime.TotalHours)) Mod 60, CInt(Math.Floor(ElapsedTime.TotalMinutes)) Mod 60, CInt(Math.Floor(ElapsedTime.TotalSeconds)) Mod 60)
   End Function
#End Region
 
#Region " Remaining Time Function "
 
   Public Function Print_Remaining_Time()
       If EndTime.ToString = "01/01/0001 0:00:00" Then
           EndTime = Now
           EndTime = EndTime.AddMilliseconds(Time_Out - 1000)
       End If
       RemainingTime = Now().Subtract(EndTime)
       Return String.Format("{0:00}:{1:00}:{2:00}", CInt(Math.Floor(RemainingTime.TotalHours)) Mod 60, CInt(Math.Floor(RemainingTime.TotalMinutes)) Mod 60, CInt(Math.Floor(RemainingTime.TotalSeconds)) Mod 60)
   End Function
 
#End Region

Eleкtro:
Ya está solucionado...

Cambiar:
Código:

RemainingTime = Now().Subtract(EndTime)

Por:
Código:

RemainingTime = EndTime.Subtract(Now)

Saludos.

Crazy.sx:
Yo hice un código muy largo para poder hacer esto tan simple jaja que al final era algo tonto. Jeje.

Saludos.

Navegación

[0] Índice de Mensajes