Chrono qui compte trop vite!

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
ThoT
Messages : 33
Inscription : mar. 20/mars/2007 17:51

Chrono qui compte trop vite!

Message par ThoT »

Bonsoir a tous!
Voila un essai de chronometre (qui biensur ne fonctionne pas!)
Je poste le code car je ne trouve pas la cause du probleme...

Code : Tout sélectionner

Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #String_0
  #String_1
  #String_2
  #String_3
  #Button_0
  #Button_1
  #Button_2
EndEnumeration


Procedure Open_Window_0()
  If OpenWindow(#Window_0, 467, 200, 300, 150, "Chronometre",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      StringGadget(#String_0, 10, 20, 70, 70, "")
      StringGadget(#String_1, 90, 20, 70, 70, "")
      StringGadget(#String_2, 170, 20, 70, 70, "")
      StringGadget(#String_3, 250, 50, 40, 40, "", #PB_String_ReadOnly | #PB_String_Numeric)
      ButtonGadget(#Button_0, 10, 100, 70, 30, "")
      ButtonGadget(#Button_1, 90, 100, 70, 30, "")
      ButtonGadget(#Button_2, 170, 100, 70, 30, "")
      
    EndIf
  EndIf
EndProcedure

temps_de_ref = ElapsedMilliseconds()
ms = 0
s = 0
m = 0
h = 0

open_window_0()

Repeat

evenement = WindowEvent()


ms = ElapsedMilliseconds() - temps_de_ref

If ms > 999
ms = 0
s = s + 1
EndIf

If s > 59
s = 0
m = m + 1
EndIf

If m > 59
m = 0
h = h + 1
EndIf

If h > 24
h = 0
EndIf

SetGadgetText(#String_0,Str(h))

SetGadgetText(#String_1,Str(m))

SetGadgetText(#String_2,Str(s))

SetGadgetText(#String_3,Str(ms))

If evenement = #PB_Event_CloseWindow
Break
EndIf
ForEver
Je me doute bien que ca va vous paraitre tout bete a resoudre, donc si vous pouviez m'expliquer, je vous serais reconnaissant!

Merci d'avance :D
tmyke
Messages : 1554
Inscription : lun. 24/juil./2006 6:44
Localisation : vosges (France) 47°54'39.06"N 6°20'06.39"E

Message par tmyke »

Entre le fromage et le dessert, j'ai modifié vite fait ton code, ce qui donne
ceci:

Code : Tout sélectionner

Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #String_0
  #String_1
  #String_2
  #String_3
  #Button_0
  #Button_1
  #Button_2
EndEnumeration


Procedure Open_Window_0()
  If OpenWindow(#Window_0, 467, 200, 300, 150, "Chronometre",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      StringGadget(#String_0, 10, 20, 70, 70, "")
      ;StringGadget(#String_1, 90, 20, 70, 70, "")
      ;StringGadget(#String_2, 170, 20, 70, 70, "")
      ;StringGadget(#String_3, 250, 50, 40, 40, "", #PB_String_ReadOnly | #PB_String_Numeric)
      ButtonGadget(#Button_0, 10, 100, 70, 30, "")
      ButtonGadget(#Button_1, 90, 100, 70, 30, "")
      ButtonGadget(#Button_2, 170, 100, 70, 30, "")
     
    EndIf
  EndIf
EndProcedure

temps_de_ref = ElapsedMilliseconds()
ms = 0
s = 0
m = 0
h = 0

open_window_0()

Repeat

evenement = WindowEvent()


ms = ElapsedMilliseconds() - temps_de_ref

If ms > 999
  ms = 0
  temps_de_ref = ElapsedMilliseconds()
  s = s + 1
EndIf

If s > 59
  s = 0
  m = m + 1
EndIf

If m > 59
  m = 0
  h = h + 1
EndIf

If h > 24
  h = 0
EndIf

total$ = Str(h)+" "+Str(m)+" "+Str(s)+" "+Str(ms)
SetGadgetText(#String_0, total$ )



If evenement = #PB_Event_CloseWindow
Break
EndIf
ForEver 
Une des erreur que tu as faite (un oubli en fait), c'est de ne pas ré-initialiser ta réference temps:

Code : Tout sélectionner

If ms > 999
  ms = 0
  temps_de_ref = ElapsedMilliseconds()
  s = s + 1
EndIf
cette ligne temps_de_ref = ElapsedMilliseconds() est très importante...

;)
Force et sagesse...
Répondre