bigboy123 Posted November 21, 2009 at 04:06 PM Report Share #297100 Posted November 21, 2009 at 04:06 PM Boas, Tou a desenvolver um projecto em que faz a contagem decrescente dos dias , horas , minutos e segundos. No projecto dias corresponde a txtdias.text, horas corresponde a txthoras.text, minutos corresponde a txtminutos.text e segundos corresponde a txtsegundos.text. Eu já consegui fazer a contagem decrescente apenas para os minutos e segundos, o problema é que não estou a conseguir fazer as horas... Ai está o código já realizado : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim dias As Integer = Val(txtdias.Text) Dim horas As Integer = Val(Txthoras.Text) Dim minutes As Integer = Val(txtminutos.Text) Dim seconds As Integer = Val(txtsegundos.Text) If dias = 0 And horas = 0 And minutes = 0 And seconds = 0 Then MsgBox("Time Ended") Timer1.Stop() End If If seconds = 0 Then minutes -= 1 seconds += 60 End If If minutes = 0 And minutes <> -1 Then horas -= 1 minutes += 59 End If seconds -= 1 If horas <> -1 Then Txthoras.Text = horas txtminutos.Text = minutes txtsegundos.Text = seconds End If If minutes <> -1 Then txtminutos.Text = minutes txtsegundos.Text = seconds End If End Sub O que acontece é que se eu meter 1 hora, 1 minuto e 5 segundos (por exemplo) quando passa 1 hora e fica 0 os minutos voltam a contar dos 59 minutos enquanto deveria ficar no 0, 🙂 :) Alguém consegue dar-me uma ajuda ? Link to comment Share on other sites More sharing options...
softklin Posted November 21, 2009 at 05:17 PM Report Share #297105 Posted November 21, 2009 at 05:17 PM Usa a classe/estrutura DateTime. http://articles.techrepublic.com.com/5100-10878_11-6089546.html Tem métodos para não te precisares de preocupar com contas de horas, minutos e segundos. POr exemplo, podes iniciar uma variável do tipo date time com a hora que queres, e fazer subtracções de horas, segundos, etc Nick antigo: softclean | Tens um projeto? | Wiki P@P Ajuda a comunidade! Se encontrares algo de errado, usa a opção "Denunciar" por baixo de cada post. Link to comment Share on other sites More sharing options...
bigboy123 Posted November 21, 2009 at 05:32 PM Author Report Share #297107 Posted November 21, 2009 at 05:32 PM Softclean obrigado mas já resolvi o problema. Tirei a contagem para dias e fiz apenas para horas, minutos e segundos. No código alterei o seguinte : If minutos = 0 And horas = 0 Then minutos = 0 horas -= 1 ElseIf minutos = -1 And horas >= 1 Then minutos = 59 horas -= 1 End If 🙂 :) 😛 :P 😛 :P 😛 :P 😛 :P 😛 :P 😛 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