use thread to check multiple time

Just starting out? Need help? Post your questions and find answers here.
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

use thread to check multiple time

Post by Micko »

hi Guy !
i guess you are feel good. For me i would like to have your help.

Code: Select all

Enumeration
  #Window_0
EndEnumeration
Enumeration
  #StatusBar_Window_0
EndEnumeration
Enumeration
  #ListIcon_0
EndEnumeration
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
Global LastElem_
PBHeure$ = FormatDate("%hh:%ii:%ss", Date())

Procedure.s GetTimeString()
  GetLocalTime_(@s.SYSTEMTIME)
  Hour$ = Str(s\wHour)
  Minute$ = Str(s\wMinute)
  Second$ = Str(s\wSecond)
  If Len(Hour$) = 1 : Hour$ = "0"+Hour$ : EndIf
  If Len(Minute$) = 1 : Minute$ = "0"+Minute$ : EndIf
  If Len(Second$) = 1 : Second$ = "0"+Second$ : EndIf
  Time$ = Hour$+":"+Minute$+":"+Second$;+" "
  ProcedureReturn Time$
EndProcedure

Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 643, 30, 372, 288, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
    If CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0))
    EndIf
    ListIconGadget(#ListIcon_0, 20, 25, 335, 215, "N°",100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
       AddGadgetColumn(#ListIcon_0, 1, "Time", 100)
    AddGadgetItem(#ListIcon_0, -1, "1" + Chr(10)+"10:53:15")
    AddGadgetItem(#ListIcon_0,  1, "2" + Chr(10)+"10:53:25")
    AddGadgetItem(#ListIcon_0,  2, "3" + Chr(10)+"10:53:35")
    AddGadgetItem(#ListIcon_0,  3, "4" + Chr(10)+"10:53:45")
    AddGadgetItem(#ListIcon_0,  4, "5" + Chr(10)+"10:53:55")
  EndIf
EndProcedure

Procedure GetTime_(Parameter)
LastElem_ = CountGadgetItems(#ListIcon_0) -1
Repeat
   For ElemPosition_ = 0 To LastElem_
      If GetGadgetItemText(#ListIcon_0,ElemPosition_,1) = GetTimeString()
         Debug "Time mismatch" 
          Else  
         Debug "Time not found"
      EndIf
         ;Debug GetGadgetItemText(#ListIcon_0,ElemPosition_,1)
         ;Debug GetTimeString()
     Delay(1000)
   Next
Until  ElemPosition_ = 0 
EndProcedure

OpenWindow_Window_0()
monthread = CreateThread(@ GetTime_(),255)

;If ElemPosition_ = -1
;KillThread(monthread)
;EndIf

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #ListIcon_0
      EndIf
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        Break
      EndIf
  EndSelect
ForEver
Edit to change "Time mismatch" to "Time found"

what i want to do is check and display "Time found" when the define time(5 times display in ListIcon) correspond to the system time
thanks in advance. have a good day !
Last edited by Micko on Thu Feb 19, 2009 11:16 am, edited 1 time in total.
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

I'm not sure why you need to do that.

time resolution by default is something like 16 to 20 milliseconds resolution.

if you really want to get a more accurate time resolution you need to set the timeperiod at the start of you program.

and then you need to check for times between times rather than exact matches.

call this at the start of your program

Code: Select all

 
timeGetDevCaps_(@tt, SizeOf(TIMECAPS))
timeBeginPeriod_(tt\wPeriodMin)  

[/code]
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

hi Idle !
thanks for your reply.
this is exactly what i try to do :
I want to display "found time" whenever the system time is the the same with the listIcon time
i think this part need some structure

Code: Select all

timeBeginPeriod_(tt\wPeriodMin)
Sorry for ma bad English
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I would recommend that you store your elements not as text only,
but as structured elements that contain a timeformat field, too.
that would make it easy because you'll only need to compare two integer values.
for displaying in the listgadget, you can make a string out of it before sending it to the gadget.
oh... and have a nice day.
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

thanks Kaeru Gaman
this is an other very basic solution from brossden of French forum

Code: Select all

Enumeration 
  #Window_0 : #StatusBar_Window_0 : #ListIcon_0 
EndEnumeration 

Define.l Event, EventWindow, EventGadget, EventType, EventMenu 

Procedure OpenWindow_Window_0() 
  If OpenWindow(#Window_0, 643, 30, 372, 288, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar) 
    If CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0)) 
    EndIf 
    ListIconGadget(#ListIcon_0, 20, 25, 335, 215, "N°",100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect) 
    AddGadgetColumn(#ListIcon_0, 1, "Time", 100) 
    AddGadgetColumn(#ListIcon_0, 2, "", 300) 
    AddGadgetItem(#ListIcon_0, -1, "1" + Chr(10)+"13:20:25") 
    AddGadgetItem(#ListIcon_0,  1, "2" + Chr(10)+"14:20:35") 
    AddGadgetItem(#ListIcon_0,  2, "3" + Chr(10)+"15:20:25") 
    AddGadgetItem(#ListIcon_0,  3, "4" + Chr(10)+"16:23:25") 
    AddGadgetItem(#ListIcon_0,  4, "5" + Chr(10)+"20:23:25") 
  EndIf 
EndProcedure 

Procedure GetTime_(Parameter) 
  Repeat 
    x=CountGadgetItems(#ListIcon_0) 
    time=Date() 
    h=Hour(time) : m=Minute(time) : s=Second(time) 
    For n=0 To x-1 
      Debug GetGadgetItemText(#ListIcon_0,n,1) 
      hl = Val(Mid(GetGadgetItemText(#ListIcon_0,n,1),1,2)) 
      ml = Val(Mid(GetGadgetItemText(#ListIcon_0,n,1),4,2)) 
      sl = Val(Mid(GetGadgetItemText(#ListIcon_0,n,1),7,2)) 
      If h>hl Or ( h=hl And m>ml ) Or (h=hl And m=ml And s>sl) 
        SetGadgetItemText(#ListIcon_0,n,"L'heure a sonné",2) 
      Else 
        SetGadgetItemText(#ListIcon_0,n,"Pas encore",2) 
      EndIf 
    Next 
    Delay(1000) 
  ForEver 
EndProcedure 
OpenWindow_Window_0() 
CreateThread(@ GetTime_(),255) 
Repeat 
  Event = WaitWindowEvent() 
  If Event = #PB_Event_CloseWindow 
         break
        CloseWindow(#Window_0) 
  EndIf 
ForEver
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

Hi Guy !
here i wan't to display a message "It is time" when time is found but not every second

Code: Select all

Enumeration 
  #Window_0 : #StatusBar_Window_0 : #ListIcon_0 
EndEnumeration 
Global ExecuteProgram = 0
Define.l Event, EventWindow, EventGadget, EventType, EventMenu 

Procedure OpenWindow_Window_0() 
  If OpenWindow(#Window_0, 643, 30, 372, 288, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar) 
    If CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0)) 
    EndIf 
    ListIconGadget(#ListIcon_0, 20, 25, 335, 215, "N°",100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect) 
    AddGadgetColumn(#ListIcon_0, 1, "Time", 100) 
    AddGadgetColumn(#ListIcon_0, 2, "", 300) 
    AddGadgetItem(#ListIcon_0, -1, "1" + Chr(10)+"16:22:05") 
    AddGadgetItem(#ListIcon_0,  1, "2" + Chr(10)+"15:22:10") 
    AddGadgetItem(#ListIcon_0,  2, "3" + Chr(10)+"15:21:25") 
    AddGadgetItem(#ListIcon_0,  3, "4" + Chr(10)+"15:48:35") 
    AddGadgetItem(#ListIcon_0,  4, "5" + Chr(10)+"16:48:25") 
  EndIf 
EndProcedure 

Procedure GetTime_(Parameter) 
;ExecuteProgram:
  Repeat 
    x=CountGadgetItems(#ListIcon_0) 
    time=Date() 
    h=Hour(time) : m=Minute(time) : s=Second(time) 
    For n=0 To x-1 
      Debug GetGadgetItemText(#ListIcon_0,n,1) 
      hl = Val(Mid(GetGadgetItemText(#ListIcon_0,n,1),1,2)) 
      ml = Val(Mid(GetGadgetItemText(#ListIcon_0,n,1),4,2)) 
      sl = Val(Mid(GetGadgetItemText(#ListIcon_0,n,1),7,2)) 
      If  (h=hl And m=ml And s>sl)
         SetGadgetItemText(#ListIcon_0,n,"It is time",2)
         If MessageRequester("AutoStart","It is time"); this message should appear one time if time is found but not every second
            ;break
         EndIf 
      Else  
        SetGadgetItemText(#ListIcon_0,n,"It isn't time",2) 
        EndIf
     Next 
    Delay(1000) 
  ForEver 
EndProcedure 
OpenWindow_Window_0() 
MyThread = CreateThread(@ GetTime_(),255) 

Repeat 
  Event = WaitWindowEvent() 
  If Event = #PB_Event_CloseWindow 
        CloseWindow(#Window_0) 
          Break
   EndIf 
ForEver 
thanks
Post Reply