Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keeping track of time / two things at once
#1
I am writing a program that collects data for work. One item is the length of a call. The program will be running whether we are on the phone or not, so only part of it needs to keep track of time. So, here's the dilemma: how do I get part of the program to count the hours and/or minutes and/or seconds we are on the phone while still running the rest of the program?

Shaggy
An ounce of clear thinking is worth a pound of research into the mysteries of the obvious."
--THOMAS SZASZ, MD.
New York Times
May 29, 2001
Reply
#2
Code:
DO
    IF phoneRings% THEN callStartTime% = TIMER
    IF phoneHungUp% THEN
        callLength% = TIMER - callStartTime%
        PRINT "You have been on the phone for"; STR$(callStartTime%); "seconds."
    END IF
LOOP

You can use that concept to get the seconds the phone call lasted. You can then manipulate the seconds to get minutes and hours, etc. Smile
earn.
Reply
#3
You could do an event-tapping type thing where the program just loops until an event happens, like hanging up the phone or an employee checks in. Sort of like Seph said, except you put other stuff in the loop also.

Another alternative would be to have seperate programs running at the same time. You can have them write to a file or use global vars if they need to communicate.
Reply
#4
seph and RST,

I tried the idea of a loop before. It didn't work. My program is just a giant loop made of lots of small ones. Putting another loop in it using TIMER (and looping it around several other loops) seemed to take up a lot of space for such a simple task. I was looking for a simpler way. I am actually writing two programs, one to write the data and one to read it. Perhaps I could just make the reader figure out the total time.

Anyway, thanks for the help. Keep an eye out for later messages about the second program (the data reader).

Shaggy
An ounce of clear thinking is worth a pound of research into the mysteries of the obvious."
--THOMAS SZASZ, MD.
New York Times
May 29, 2001
Reply
#5
The thing is, you treat my small loop as your large loop.
earn.
Reply
#6
Quote:The thing is, you treat my small loop as your large loop.

Actually, the things is, the timer loop in my project has to be set off by a keystroke (meaning I have to use a string). I get a type mismatch trying to use a string and an interger together, so your idea, although good, won't work in my program. To set off the timer loop with a string took me several more lines of code that returned 0 as the total time.

If you can tell me how to get the program to set off the timer loop with a keystroke, and still return the actual time on the phone at the end (instead of 0, like my first idea did), it would be greatly appreciated.

Shaggy
An ounce of clear thinking is worth a pound of research into the mysteries of the obvious."
--THOMAS SZASZ, MD.
New York Times
May 29, 2001
Reply
#7
Code:
PRINT "Press a key to start timer..."
do: loop until inkey$ <> ""
StartTime = TIMER

PRINT "Press a key when you hang up the phone."
do: loop until inkey$ <> ""
ElapsedTime = TIMER - StartTime

PRINT "You were on the phone for"; ElapsedTime; "seconds."

Is this what you had in mind? If it is and you need help with any of it, just ask. Smile
Reply
#8
RST,

FABULOUS! :bounce: Except I need to modify it a little to look for a specific keystroke to start and finish the call and put the start and finish in specific parts of the program... but, don't worry, I've got that covered. It didn't even occur to me to use a non-string non-integer (i.e. just StartTime instead of StartTime$ or StartTime%).

Well, that's why I picked the signature I have.

Shaggy
An ounce of clear thinking is worth a pound of research into the mysteries of the obvious."
--THOMAS SZASZ, MD.
New York Times
May 29, 2001
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)