timer while dragging a window
BlitzPlus Forums/BlitzPlus Programming/timer while dragging a window
| ||
I only have crappy 56k line here, however, to lower the regular 2-monthly 200$+ phonebill, a company offers a better deal: you buy a fixed amount of phonehours and that's all. In my case, I have 100 hours for 50$ per month. Day or night doesn't make a difference.. Anyway, ofcourse, you can't take unused hours to the next month, and if you exceed the 100hour barrier, you gotta pay extra. Ofcourse, these companies want you to exceed since they can get more $ then.., so, logically they won't tell you how many hours you already used.. After I tried a one-month solution by writing down all used time in notepad, here's my hacky B+ solution.. when you go online, press 'start' and when you disconnect, press 'stop'. However.. the timer doesn't update when you drag the app-window around.. how do I fix this? sw=ClientWidth(Desktop()) sh=ClientHeight(Desktop()) app=CreateWindow("Counter",(sw/2)-70,(sh/2)-40,126,80,0,1) quit=False panel=CreatePanel(0,0,130,80,app):SetPanelColor panel,128,160,192:SetGadgetLayout panel,1,0,1,0 start=CreateButton("start",4,4,40,24,panel) disconnect=CreateButton("stop",48,4,40,24,panel) minimize=CreateButton("_",96,6,20,20,panel) timerfile$="c:\My Documents\CS_TBL_counter.dat" f=ReadFile(timerfile$) If Not f f=WriteFile (timerfile$) WriteLine f,0 CloseFile f f=ReadFile(timerfile$) Else seconds=ReadLine$(f) CloseFile f EndIf DisableGadget disconnect startlabel=CreateLabel(seconds+" ( "+secs2time(seconds)+" )",4,32,112,20,panel,3) Repeat WaitEvent() If EventID()=$803 If EventSource()=app f=WriteFile(timerfile$) WriteLine f,seconds CloseFile f quit=True EndIf EndIf If EventID()=$401 If EventSource()=start timer=CreateTimer(1) DisableGadget start EnableGadget disconnect EndIf If EventSource()=disconnect If timer FreeTimer timer f=WriteFile(timerfile$) WriteLine f,seconds CloseFile f DisableGadget disconnect EnableGadget start EndIf If EventSource()=minimize MinimizeWindow app EndIf EndIf If EventID()=$4001 If EventSource()=timer seconds=seconds+1 SetGadgetText startlabel,seconds+" ( "+secs2time(seconds)+" )" EndIf EndIf Until quit End Function secs2time$(s) hours= s / 3600 mins = (s / 60) Mod 60 secs = s Mod 60 Return addzero(hours,3)+":"+addzero(mins,2)+":"+addzero(secs,2) End Function Function addzero$(s$,l) s$=RSet$(s$,l) s$=Replace$(s$," ","0") Return s$ End Function |
| ||
Here you go, this uses a self syncronising timer based on millisecs, and one which I use for all timing.sw=ClientWidth(Desktop()) sh=ClientHeight(Desktop()) app=CreateWindow("Counter",(sw/2)-70,(sh/2)-40,126,80,0,1) quit=False panel=CreatePanel(0,0,130,80,app):SetPanelColor panel,128,160,192:SetGadgetLayout panel,1,0,1,0 start=CreateButton("start",4,4,40,24,panel) disconnect=CreateButton("stop",48,4,40,24,panel) minimize=CreateButton("_",96,6,20,20,panel) timerfile$="c:\My Documents\CS_TBL_counter.dat" f=ReadFile(timerfile$) If Not f f=WriteFile (timerfile$) WriteLine f,0 CloseFile f f=ReadFile(timerfile$) Else seconds=ReadLine$(f) CloseFile f EndIf DisableGadget disconnect Seconds=0 startlabel=CreateLabel(seconds+" ( "+secs2time(seconds)+" )",4,32,112,20,panel,3) Global LastTime Repeat WaitEvent() If EventID()=$803 If EventSource()=app f=WriteFile(timerfile$) WriteLine f,seconds CloseFile f quit=True EndIf EndIf If EventID()=$401 If EventSource()=start timer=CreateTimer(5) LastTime=MilliSecs() DisableGadget start EnableGadget disconnect EndIf If EventSource()=disconnect If timer FreeTimer timer f=WriteFile(timerfile$) WriteLine f,seconds CloseFile f DisableGadget disconnect EnableGadget start EndIf If EventSource()=minimize MinimizeWindow app EndIf EndIf If EventID()=$4001 If EventSource()=timer Seconds=UpdateSeconds(Seconds) SetGadgetText startlabel,seconds+" ( "+secs2time(seconds)+" )" EndIf EndIf Until quit End Function UpdateSeconds(Secs) ThisTime=MilliSecs()-LastTime If ThisTime=>1000 Repeat Secs=Secs+1 ThisTime=ThisTime-1000 Until ThisTime<1000 LastTime=MilliSecs()-ThisTime EndIf Return Secs End Function Function secs2time$(s) hours= s / 3600 mins = (s / 60) Mod 60 secs = s Mod 60 Return addzero(hours,3)+":"+addzero(mins,2)+":"+addzero(secs,2) End Function Function addzero$(s$,l) s$=RSet$(s$,l) s$=Replace$(s$," ","0") Return s$ End Function |
| ||
There are freeware utilities that log your time online automatically: http://www.simtel.net/product.download.mirrors.php?id=11819 there's loads more if you search. Luckily enough my isp gives access to a log which is quite handy. okee |
| ||
My ISP (Tiscali UK) gives me a log. But it doesn't correspond to my bill. I got charged for 2 hours extra last month, but when I add up their figures (even if I do some crazy rounding up), I'm at least 4-5 hours under my 50 hour limit... grrr. |