VB6 Creare un timer

Alby2691

Utente Attivo
2
0
CPU
AMD 4600x2
Scheda Madre
Abit KN9 Ultra
HDD
400gb
RAM
3gb 800mhz
GPU
Galaxy 8800gt
PSU
Enermax NoisTakerII 600w
Case
Non ricordo la marca...cmq da modding *.*
OS
Windows...
Ciao a tutti, sto provando a creare un programma in visual basic 6 che da quando viene cliccato il pulsante "Start" comincia a contare il tempo (hh-mm-ss) e in contemporanea, partendo da 14m e 59s, mi scali quel tempo fino a 0m e 0s dove, a quel punto, aumenta di uno un contatore, e ricomincia a scalare il tempo da 0. Sono riuscito a scrivere una gran parte di codice e gira tutto bene......per i primi 5/6 minuti, dopodichè il conteggio del tempo incomincia ad avere 2 secondi in meno, e il contdown dei 15m ad essere 2 secondi sopra il normale(ho usato un cronometro per controllare). Ho cercato un paio di soluzioni ma il codice mi sembra giusto cosi. Quindi chiedo a voi esperti :ok: se sapete risolvere questo problema. Oppure se conosciete un altro metodo per costruire questo programma ^^

Metto in spiler il codice che ho scritto :
Codice:
Dim th As Long 'tempo in ore per ogni sessione
Dim tm As Long 'tempo in minuti per ogni sessione
Dim ts As Long 'tempo in secondi per ogni sessione
Dim sc As Long 'contatore degli scatti
Dim tm2 As Long 'tempo in minuti per contare gli scatti
Dim ts2 As Long 'tempo in secondi per contare gli scatti
Dim tm3 As Long 'tempo in minuti per calcolare tempo residuo
Dim ts3 As Long 'tempo in secondi per calcolare tempo residuo

Private Sub cmdstart_Click()
Timer1.Enabled = True
Timer2.Enabled = True
Timer3.Enabled = True
End Sub

Private Sub cmdstop_Click()
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub


Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
th = 0
tm = 0
ts = 0
tm2 = 0
ts2 = 0
tm3 = 14
ts3 = 60
sc = 1
End Sub


Private Sub timer1_timer()

ts = ts + 1
If ts = 59 Then
    tm = tm + 1
    ts = 0
End If
If tm = 59 Then
    th = th + 1
    tm = 0
End If

lbltempom.Caption = tm & "m"
lbltempos.Caption = ts & "s"
lbltempoh.Caption = th & "h"

End Sub
Private Sub Timer2_Timer()
ts2 = ts2 + 1
If ts2 = 60 Then
    tm2 = tm2 + 1
    ts2 = 0
    If tm2 = 15 Or tm2 = 30 Or tm2 = 45 Or tm2 = 60 Then
        sc = sc + 1
    End If
End If
If tm2 = 60 Then
    tm2 = 0
End If
lblscatti.Caption = sc
End Sub

Private Sub Timer3_Timer()
lbltemporimm.Caption = tm3 & "m"
lbltemporims.Caption = ts3 & "s"

ts3 = ts3 - 1
If ts3 = 0 Then
    lbltemporims = ts3 & "s"
    tm3 = tm3 - 1
    If tm3 = -1 Then
        tm3 = 2
    End If
    ts3 = 60
End If
If tm3 = 0 And Not ts3 = 0 Then
    lbltemporimm.Caption = 0
End If

lbltemporimm.Caption = tm3 & "m"
lbltemporims.Caption = ts3 & "s"

End Sub
 

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!