Jump to content

Simplest timer (just curious about how someone else would do this)


Newb
 Share

Recommended Posts

I've made a simple code to beep as an alarm clock on a time I decide (to take pauses while programming) and I would like to know if anyone else has faster, shorter, more intelligent or less expensive (in terms of resources used) solutions. Anything better or different is accepted. Just curious.

Dim $time[2]=[TimerInit(),TimerDiff($time[0])]
While $time[1]<3000
$time[1]=TimerDiff($time[0])
Sleep(100)
Wend
Beep(2400,2000)

Here is mine. One thing is, $time[1] is used too soon (but autoit makes it run, so i left it there), the correct version should be like this

Dim $time[2]=[TimerInit()]
$time[1]=TimerDiff($time[0])
While $time[1]<3000
$time[1]=TimerDiff($time[0])
Sleep(100)
Wend
Beep(2400,2000)

I even tried to make a version with inputbox but autoit mess it up big time, as always with converting from string to numbers (always had problem doing it smooth...) to compile into an exe for future use, so I'll keep it running from Scite.

This was the inputbox version:

Dim $time[3]=[Number(InputBox("Timer Set","How many seconds you want the alarm to beep?")),TimerInit(),TimerDiff($time[0])]
While $time[2]<$time[0]*1000
$time[2]=TimerDiff($time[1])
Sleep(100)
Wend
Beep(2400,2000)

Tried to fix it in 2023090239 different ways. Never worked, timer still sounds instantly.

(Put Int instead of number, Put Number/int in the while instead of the array, Tried to declare arrays subcripts separately etc. etc.) I did anything that came up in my mind and I wasn't able to find a solution.

So another question would be, why autoit hates numbers, or why autoit numbers/int conversion does the work but this still doesn't work?

Thank you all, expecially MVP, for being as awesome as you are.

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Link to comment
Share on other sites

Try this out for size:

NOTE: see comments in the script

Global $time[3] = [InputBox("Timer Set", "How many seconds do you want wait until the alarm beeps?"), TimerInit(), ""] ; changed the prompt to reflect what you're actually setting
$time[2] = TimerDiff($time[1]) ; $time[1] doesn't hold a value until you declare it, so you can't set the TimerDiff in the same declaration as the array above
While $time[2] < ($time[0] * 1000)
    $time[2] = TimerDiff($time[1])
    Sleep(100)
WEnd
Beep(2400, 2000)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 2 weeks later...

Ok thanks, much appreciated.

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...