almamater Posted October 29, 2009 at 11:03 PM Report Share #293959 Posted October 29, 2009 at 11:03 PM 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 More sharing options...
Gooden Posted October 30, 2009 at 10:26 AM Report Share #293985 Posted October 30, 2009 at 10:26 AM 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 More sharing options...
almamater Posted October 30, 2009 at 06:56 PM Author Report Share #294083 Posted October 30, 2009 at 06:56 PM 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 More sharing options...
Gooden Posted October 30, 2009 at 07:04 PM Report Share #294086 Posted October 30, 2009 at 07:04 PM e então? sabes onde está o 19,0,0? mete as horas a que começou. por exemplo= hourstar.hour etc.... vai-te mostrar o tempo que já percorreu desde o inicio Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now