Jump to content

Time Remaining


almamater
 Share

Recommended Posts

Olá..

estou a fazer um processo e queria associar o tempo restante ao mesmo.

Tenho uma listbox onde adiciono vários items e percorro a mesma do 1º ao último e quero mostrar o tempo que falta até concluir isto...

Estou a fazer assim:

   public start_time As DateTime
    Public stop_time As DateTime
    Public elapsed_time As TimeSpan

Ao iniciar o processo num botão activo a contagem:

stop_time = Now

e chamo o processo de cálculo ao mesmo tempo que passa de 1 item para outro na listbox:

       

        Dim TotalItems As Integer = ListBox.Items.Count
        Dim ItemActual As Integer = ListBox.SelectedIndex + 1

        elapsed_time = stop_time.Subtract(start_time)
        Dim TempoGasto As Integer = elapsed_time.TotalSeconds.ToString("0.00") '("0.000000")

        Dim valor1, valor2, resultado As Integer

        Dim ItemsRestantes As Integer = TotalItems - ItemActual 

        valor1 = TempoGasto / ItemActual 
        valor2 = valor1 * ItemsRestantes 

        resultado = valor2 /60

Mas isto não está a bater certo.. os valores que devolve não são os segundos que faltam para terminar  😄

Estou a fazer errado desta forma?

Abraço

Link to comment
Share on other sites

mete isto num timer com interval de 1000....

vai te retomar quanto falta até eu sair do trabalho... LOOOOOOL

PS: Método rudimentar mas funcional xD

Dim date1 As Date = New Date(Date.Now.Year, Date.Now.Month, Date.Now.Day, 19,0, 0)
        Dim date2 As Date = Date.Now
        If date1 < date2 Then
            date1 = date1.AddDays(1)
        End If
        Dim a As TimeSpan
        a = date1.Subtract(date2)
        Dim strf(1) As String
        strf = a.ToString.Split(".")
        Label3.Text = strf(0).Replace("-", "")
Link to comment
Share on other sites

mete isto num timer com interval de 1000....

vai te retomar quanto falta até eu sair do trabalho... LOOOOOOL

PS: Método rudimentar mas funcional xD

Dim date1 As Date = New Date(Date.Now.Year, Date.Now.Month, Date.Now.Day, 19,0, 0)
        Dim date2 As Date = Date.Now
        If date1 < date2 Then
            date1 = date1.AddDays(1)
        End If
        Dim a As TimeSpan
        a = date1.Subtract(date2)
        Dim strf(1) As String
        strf = a.ToString.Split(".")
        Label3.Text = strf(0).Replace("-", "")

Ok isso faz uma contagem decrescente! Mas o que queria mesmo mesmo era calcular o tempo restante segundo o tempo que já passou (elapsed time) de acordo com os Items que ainda falta percorrer na ListBox..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.