Forum at OOoForum.orgThe Forum
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Timer & click counter Macro's?

Post new topic   Reply to topic Forum Index -> Macros and API
View previous topic :: View next topic  
Author Message
Power User
Power User

Joined: 13 Jan 2012
Posts: 98

PostPosted: Wed Jan 18, 2012 10:17 pm    Post subject: Timer & click counter Macro's? Reply with quote

Hello, I would like to ask for some help on a couple of macro's that seem complicated to me. First I would like to request that any reply's made with macros in them to be written with a lot of detail. As I am learning and have not fully come to understand all of the short hand and lingo that many here employ, written or otherwise.

Second I would like to thank you for taking the time and assisting me in any capacity, as I know you are helping out of your own time. Thank you.

Third, If these questions have been asked before, please forgive me. I have tried to search for answers but like I said earlier I do not fully understand how macros are written so I tend to get lost very easily in explanations and can't bridge the gap to apply it to my problems.

What I am looking for is two fold.

First I would like to have a timer within a calc spreadsheet. I noticed that if I bring up the control toolbar there is a "clock" that I can insert into the spreadsheet but I am unsure of how to make it work. Plus I want to be able to set it as a timer that counts down. This timer I would like to make it modifiable so as to change the amount of time, pause it, reset it or to stop it. (think stop watch)

I would also like to have a second timer built in, so that after a set amount of time goes by a counter cell goes up by 1 each time.

For example: If I set the timer to "two" minutes and press start, the timer starts counting down to "zero" and once it hits zero a "1" appears in my counter cell and the timer starts over again at two minutes counting down to zero. And once again when it hits zero the "1" in the counter cell goes up and becomes a "2" and so on, until I stop it or pause it or change it.

Which brings me to the second part of my request. I have several buttons on a page that changes certain fields. I would like to have a record of how many times those buttons are pushed.

For Instance: I would like to a have counter cell under each one. So that when a button is pushed that cell adds a "1" to it, much like the counter cell in my earlier request.

Like I said, this seems complicated to me and I am not even sure if it can be accomplished in the way that I am envisioning it. So If you don't think it will work but have another idea that might suit my needs, please pass them along.

Thanks for looking.
Back to top
View user's profile Send private message
Power User
Power User

Joined: 13 Jan 2012
Posts: 98

PostPosted: Thu Jan 19, 2012 4:13 pm    Post subject: Reply with quote

Ok after some research I came across this macro that someone else wrote, however they just posted code and didn't give the whole macro and when I put it in a macro, something went wrong. I am not sure how to write this in order to make it work.

Can you tell me what else I need to do in order to make this acceptable?

'Session timer with pause. Version 1.1  November 11, 2005
Global StartT, ElapsedT, T, Paused as Boolean
Private hr, hrs, min, mins, s
Sub aTimer
'User modifiable variables below. Once you are familiar with how
'the macro works you may want to change all or some to "false".
ConfirmStart  = true  'Show message on initial start.
ConfirmPause  = true  'Show message upon pausing.
ConfirmResume = true  'Show message when resuming after pause.
'==========END USER MODIFIABLE VARIABLES=============
GoSub MakeMsg
If StartT = 0 then 'Initialize timer.
  StartT = Timer
  If ConfirmStart then MsgBox(CS,,CST)
  T = Timer : End
 ElseIf NOT Paused AND Timer > T then 'In timing session so set variable.
  ElapsedT = ElapsedT + Timer - T
  'Below - Timing session has crossed midnight, i.e., Timer < T.
 ElseIf NOT Paused then ElapsedT = ElapsedT + Timer + 86400 - T
If Not Paused And ElapsedT > 0 then    'If running do what?
  iAns = MsgBox (isTiming,35,isTimingT)'Pause, continue or finish?
  If iAns = 6 then 'User click Yes so pause the timer.
    Paused = true
    If ConfirmPause then MsgBox(CP,,CPT)
   ElseIf iAns = 7 then : T = Timer : End 'User clicked No so
  EndIf                                   'resume timing.
 Else Paused = false 'Is paused so resume timing.
  If ConfirmResume then MsgBox(CR,,CRT)
  T = Timer : End
'User clicked Cancel so finialize.
If Timer > StartT then
  Idle = Timer - StartT - ElapsedT : Total = Timer - StartT
 Else Idle = Timer + 86400 - StartT - ElapsedT 'Session went across midnight.
  Total = Timer + 86400 - StartT
GoSub DoneMsg
StartT = 0 : ElapsedT = 0    'Reset global variables
T = 0 : Paused = false : END 'and normal program end.
'================GOSUB ROUTINES================
If ConfirmStart then
  CS = "The timer is starting." : CST = "STARTING TIMING SESSION."
If ConfirmPause then
  CP = "The timer is paused." : CPT = "PAUSED."
 Else SI = " (silently)"
If ConfirmResume then
 CR = "Resuming timing session." : CRT = "RESUME TIMING."
a$ = "YES will pause the timer" & SI & "." & Chr(13)
a$ = a$ & "NO will continue timing (silently)." & Chr(13)
isTiming = a$ & "CANCEL will end timing and display results."
et = GetParts(ElapsedT)
a$ = "Elapsed Time = " & hr & hrs & min & mins & et & s
et = GetParts(Idle)
b$ = "Idle time = " & hr & hrs & min & mins & et & s
c$ = "'Idle' includes time paused and responding to messages."
et = GetParts(Total)
d$ = "Total session time = " & hr & hrs & min & mins & et & s
Done = a$ & Chr(13) & b$ & Chr(13) & c$ & Chr(13) & d$
End Sub

Function GetParts(Tyme)
If Tyme > 3599 then
 hr = Int(Tyme/3600) : Tyme = Tyme mod 3600
 If hr = 1 then hrs = " hour, "
 If hr > 1 then hrs = " hours, "
If Tyme > 59 then
 min = Int(Tyme/60) : Tyme = Tyme mod 60
 If min = 1 then mins = " minute, "
 If min > 1 then mins = " minutes, "
If Tyme = 1 then s = " second."
If Tyme > 1 then s = " seconds."
GetParts = Tyme
End Function

Also I know this won't perform all the tasks that I was asking about but I may be able to adjust some of my things that I am wanting it to do. Let me know if there is a better option out there please though.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Forum Index -> Macros and API All times are GMT - 8 Hours
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group