Italian Visuallizzare missilescondo con il Timer

LucaMs

Expert
Licensed User
Longtime User
Devo rileggere meglio il problema, perché a me sembra che funzioni (purtroppo, ho fatto una cosa al volo, non è come il tuo)

Allego e rileggo :)

MODIFICATO per calcolare solo il tempo dallo Start, ma aggiungere un'ora. Devo cercare sul sito, riguarderà i fusi orari!
 

Attachments

  • LM Chrono Test.zip
    11.6 KB · Views: 370
Last edited:

lock255

Well-Known Member
Licensed User
Longtime User
Devo rileggere meglio il problema, perché a me sembra che funzioni (purtroppo, ho fatto una cosa al volo, non è come il tuo)

Allego e rileggo :)

MODIFICATO per calcolare solo il tempo dallo Start, ma aggiungere un'ora. Devo cercare sul sito, riguarderà i fusi orari!
Sembra ottimo, ora lo testo affondo per verificare che sia preciso e che non si facci influenzare dal carico del sistema :)
 

lock255

Well-Known Member
Licensed User
Longtime User
Intanto grazie! :D
Wow, mi piacerebbe capire come funziona ma è davvero troppo complesso. Ci vorrebbero i commenti :)
 
D

Deleted member 103

Guest
Ciao lock255,

se vuoi usare una routine più semplice prova questa, io la uso nelle mie App e va benissimo.

B4X:
Sub Chronometer_Tick
'  pm = PeriodBetweenWithMilliseconds(StartTime, DateTime.Now)
'    Label1.Text = FN(pm.p.Hours) & ":" & FN(pm.p.Minutes) & ":" & FN(pm.p.Seconds) & "." & _
'    NumberFormat(pm.ms, 3, 0)
   
    Label1.Text = getConvertTickToHHmmsszs(DateTime.Now - StartTime)
End Sub

Sub getConvertTickToHHmmsszs(time As Long) As String
    Dim vorzeichen As String=""
    Dim h,m,s,zs As Int
    Dim t As Long=Abs(time)
    If time < 0 Then vorzeichen="-"
    zs = t Mod 1000
    s = (t/1000) Mod 60
    m = (t/60000) Mod 60
    h = (t/3600000) Mod 24
    Return vorzeichen & NumberFormat(h,2,0) & ":" & NumberFormat(m,2,0) & ":" & NumberFormat(s,2,0) & "." & NumberFormat2(zs,3,0,0,False)
End Sub
 

lock255

Well-Known Member
Licensed User
Longtime User
Ciao lock255,

se vuoi usare una routine più semplice prova questa, io la uso nelle mie App e va benissimo.

B4X:
Sub Chronometer_Tick
'  pm = PeriodBetweenWithMilliseconds(StartTime, DateTime.Now)
'    Label1.Text = FN(pm.p.Hours) & ":" & FN(pm.p.Minutes) & ":" & FN(pm.p.Seconds) & "." & _
'    NumberFormat(pm.ms, 3, 0)
  
    Label1.Text = getConvertTickToHHmmsszs(DateTime.Now - StartTime)
End Sub

Sub getConvertTickToHHmmsszs(time As Long) As String
    Dim vorzeichen As String=""
    Dim h,m,s,zs As Int
    Dim t As Long=Abs(time)
    If time < 0 Then vorzeichen="-"
    zs = t Mod 1000
    s = (t/1000) Mod 60
    m = (t/60000) Mod 60
    h = (t/3600000) Mod 24
    Return vorzeichen & NumberFormat(h,2,0) & ":" & NumberFormat(m,2,0) & ":" & NumberFormat(s,2,0) & "." & NumberFormat2(zs,3,0,0,False)
End Sub
Grazie per il suggerimento, quando provo il tuo codice ottengo questo errore:
B4X:
Parsing code.                          Error
Error parsing program.
Error description: Undeclared variable 'starttime' is used before it was assigned any value.
Occurred on line: 47
    Label1.Text = getConvertTickToHHmmsszs(DateTime.Now - StartTime)
 

magoandroid

Member
Licensed User
Longtime User
Grazie per il suggerimento, quando provo il tuo codice ottengo questo errore:
B4X:
Parsing code.                          Error
Error parsing program.
Error description: Undeclared variable 'starttime' is used before it was assigned any value.
Occurred on line: 47
    Label1.Text = getConvertTickToHHmmsszs(DateTime.Now - StartTime)

Ciao @lock255 ,
ho sostituito nell'esempio di @Erel - @LucaMs, la routine proposta da @Filippo (ottima) e funziona correttamente senza nessun errore.
In allegato il png.

Saluti, MAgo.
 

Attachments

  • LM Chrono.png
    LM Chrono.png
    331.3 KB · Views: 306

LucaMs

Expert
Licensed User
Longtime User
Sì, funziona.
Ha un vantaggio e uno svantaggio al contempo:
il vantaggio è che non ha bisogno della libreria DateUtils, lo svantaggio è che restituisce una stringa con formato predefinito.

Potresti aggiungerla nel forum Snippets, Filippo.

(Io gli cambierei il nome in TickToMsFormat e, soprattutto, cambierei "vorzeichen" in MinusSign o Sign :D)
 
Top