Ipaq e software per cronometro

lunedì 26 novembre 2007 - 09.56

pieroalampi Profilo | Expert

Salve, ho un problema abbastanza strano, ho creato un software cronometro per il mio ipaq 6500, ma il problema è che i secondi non sono esattamente precisi, o meglio chedo che un secondo equivalga a due questo è il codice, non riesco a capire perche in win form mi funzione e sull'ipaq no
Private Sub res_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs)
Timer1.Enabled = False
az = 1
avv.Text = "Avvia"
Call azzera()
End Sub

Sub azzera()
mil = 0
sec = 0
min = 0
ore = 0
cron = 0
mil_t.Text = CStr(mil)
sec_t.Text = CStr(sec)
min_t.Text = CStr(min)
Call Controlla()
End Sub

Sub Controlla()
'Controllo millisecondi
If mil_t.Text = "0" Then mil_t.Text = "00"
If mil_t.Text = "1" Then mil_t.Text = "01"
If mil_t.Text = "2" Then mil_t.Text = "02"
If mil_t.Text = "3" Then mil_t.Text = "03"
If mil_t.Text = "4" Then mil_t.Text = "04"
If mil_t.Text = "5" Then mil_t.Text = "05"
If mil_t.Text = "6" Then mil_t.Text = "06"
If mil_t.Text = "7" Then mil_t.Text = "07"
If mil_t.Text = "8" Then mil_t.Text = "08"
If mil_t.Text = "9" Then mil_t.Text = "09"
'Controllo secondi
If sec_t.Text = "0" Then sec_t.Text = "00"
If sec_t.Text = "1" Then sec_t.Text = "01"
If sec_t.Text = "2" Then sec_t.Text = "02"
If sec_t.Text = "3" Then sec_t.Text = "03"
If sec_t.Text = "4" Then sec_t.Text = "04"
If sec_t.Text = "5" Then sec_t.Text = "05"
If sec_t.Text = "6" Then sec_t.Text = "06"
If sec_t.Text = "7" Then sec_t.Text = "07"
If sec_t.Text = "8" Then sec_t.Text = "08"
If sec_t.Text = "9" Then sec_t.Text = "09"
'Controllo minuti
If min_t.Text = "0" Then min_t.Text = "00"
If min_t.Text = "1" Then min_t.Text = "01"
If min_t.Text = "2" Then min_t.Text = "02"
If min_t.Text = "3" Then min_t.Text = "03"
If min_t.Text = "4" Then min_t.Text = "04"
If min_t.Text = "5" Then min_t.Text = "05"
If min_t.Text = "6" Then min_t.Text = "06"
If min_t.Text = "7" Then min_t.Text = "07"
If min_t.Text = "8" Then min_t.Text = "08"
If min_t.Text = "9" Then min_t.Text = "09"

End Sub

Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Call Cronometro()
Call Controlla()
End Sub

Sub Cronometro()
'inizio millisecondi
mil = mil + 1
If mil = 100 Then
sec = sec + 1
mil = 0
mil_t.Text = CStr(mil)
sec_t.Text = CStr(sec)
'inizio secondi
If sec = 60 Then
min = min + 1
sec = 0
sec_t.Text = CStr(sec)
min_t.Text = CStr(min)
'inizio minuti
If min = 60 Then
ore = ore + 1
min = 0
min_t.Text = CStr(min)
Else
min_t.Text = CStr(min)
End If
'fine minuti
Else
sec_t.Text = CStr(sec)
End If
'fine secondi
Else
mil_t.Text = CStr(mil)
End If
'fine millisecondi
End Sub

vb.net 2005
------------------------------------------------------
::::Sempre a manetta in curva::::
------------------------------------------------------

alextyx Profilo | Expert

Non ho capito se c'è un motivo per cui usi tutto quel codice. Se ho capito cosa vuoi fare, un esempio che dovrebbe funzionare è questo, realizzato con un form, quattro label, un button e un timer:

Public Class Form1

Dim Inizio As Date = Now
Dim TempoTrascorso As TimeSpan

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Inizio = Now
Timer1.Interval = 100
Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

TempoTrascorso = Now - Inizio

Me.LblOre.Text = TempoTrascorso.Hours.ToString.PadLeft(2, "0"c)
Me.LblMin.Text = TempoTrascorso.Minutes.ToString.PadLeft(2, "0"c)
Me.LblSec.Text = TempoTrascorso.Seconds.ToString.PadLeft(2, "0"c)
Me.LblMil.Text = TempoTrascorso.Milliseconds.ToString.PadLeft(3, "0"c)

End Sub
End Class

I millisecondi, comunque non potranno mai essere aggiornati con una frequenza eccessiva. Riteniamoci soddisfatti se riusciamo ad avere 5 o 6 aggiornamenti al secondo. Puoi mettere il timer a 50, anzichè 100, ma in ogni caso non potrai mai contare su una grande raffinatezza.

pieroalampi Profilo | Expert

ok per i secondi che ora sono a dir poco svizzeri, ma non capisco perche nonostante si utilizzi lo stesso metodo di calcolo e visualizzazione i millisecondi non li vepo affatto sono sempre su 000
vb.net 2005
------------------------------------------------------
::::Sempre a manetta in curva::::
------------------------------------------------------

alextyx Profilo | Expert

Io li vedo girare eccome!Se vuoi ti posto il progetto. Se da te non gira bene, è una questione di macchina, presumo. Comunque prova a mettere un Me.lblMil.Refresh alla fine della routine del timer.

pieroalampi Profilo | Expert

no qui va tutto ma no i millisecondi, in ogni caso se mi vuoi postare il cosdice palampi@21softdesign.it
vb.net 2005
------------------------------------------------------
::::Sempre a manetta in curva::::
------------------------------------------------------

alextyx Profilo | Expert

Spedito!
Rimango in curiosa attesa.
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5