need help to make reminder

Get help with using AutoHotkey and its commands and hotkeys
neosickle
Posts: 36
Joined: 01 May 2016, 14:02

Re: need help to make reminder

02 May 2016, 19:32

Exaskryz wrote:
neosickle wrote:
I tried to put gui in the script. I also put ok button into it. The size of the gui is perfect than msgbox gives for me. But the problem is when i execute the script it displays the message instantly, the gui must appear only as i indicated in my script and when i press the ok button nothing happens. It must close the window after pressing ok. Pls help. Here's what i have done.

Code: Select all


#Persistent
 


SetTimer, CheckTime, 60000
 


CheckTime:

If (A_Min = 00) OR (A_Min = 20) OR (A_Min = 40)
		
		Gui +AlwaysOnTop
		Gui, Add, Text, Center, Audit na!
		Gui, Add, Button, Default, OK
		Gui, Show
Return
The MsgBox was appearing like that because you didn't put a Block with the If statement. Use of { and } are necessary if you want more than one line to be executed only when the if statement is true.

However, you may find this is a bit problematic, because it will add the Text and Button controls repeatedly. While technically you have this in the auto-execute section, I'd suggest moving it above the label. I suggest having only the Gui, Show associated with the If statement - you also won't need a Block in that situation.

Now, that suggestion I have is what wolf's code demonstrates. It should be working; I see no reason it shouldn't be. It would be problematic though because it will actually be checking too frequently; wolf changed his timer to 1000 instead of 60000, which means that the GUI may reappear within the exact same minute after you dismiss it. So I'd suggest he put the timer back on 60000.

I executed wolf's code, and that's the behavior I got actually. A GUI that kept showing itself. With the timer on 60000 (or using the maths I originally suggested), you could have that problem resolved.
Thanks for the response bro. It did solve my prob. You are right on what you have said about wolf's. It did reappear again and again with 1000 set on timer after pressing the ok button. I am very grateful to you. But one thing i am afraid of the 60000 timer is when i execute the script less than a minute before 20, it will miss the time i have set.
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: need help to make reminder

02 May 2016, 19:37

What you can do is turn off the current timer (for CheckTime; SetTimer, CheckTimer, Off when your Gui appears, and set a brand new timer that runs once 1 minute later SetTimer, OtherTimer, -60000, whose action is merely to turn on the CheckTimer SetTimer, CheckTimer, On.
neosickle
Posts: 36
Joined: 01 May 2016, 14:02

Re: need help to make reminder

02 May 2016, 19:56

Exaskryz wrote:What you can do is turn off the current timer (for CheckTime; SetTimer, CheckTimer, Off when your Gui appears, and set a brand new timer that runs once 1 minute later SetTimer, OtherTimer, -60000, whose action is merely to turn on the CheckTimer SetTimer, CheckTimer, On.
As i have said earlier i am very new here specially on timers. So based on what wolf's given to me that is posted here, how would now my script look like if we will add the time turners? Sorry folk i really need you to show the script. Pls?
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: need help to make reminder

02 May 2016, 21:18

I won't quite piece together the answer as I think this is a good exercise for you to do. But here's an example of a timer turning itself off while turning on another timer, which will later turn back on the original timer:

Code: Select all

#Persistent

SetTimer, First, 1000
return

First:
MsgBox Hello
SetTimer, First, Off ; if you delete this line, you would keep getting the Hello message box every second
SetTimer, Second, -5000 ; this timer will run once in 5 seconds
return

Second:
SetTimer, First, On ; this will turn back on the first timer
return

Esc::ExitApp ; escape key to close this
You should expect to get a message box every 6 seconds with that code, though I haven't tested it.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: need help to make reminder

02 May 2016, 23:21

A different way to prevent the reminder from occurring several times inside the same minute would be to use a flag.
Try this:

Code: Select all

Gui +AlwaysOnTop
Gui, Add, Text, Center, Audit na!
Gui, Add, Button, Default, OK
SetTimer, CheckTime, 1000


CheckTime:
    If Mod(A_Min, 2) = 0 {          ; make testing of different intervals easier
        If Not Have_Already_Shown { ; prevent reminders from re-occuring
            Gui, Show
            Have_Already_Shown := True
        }
    } Else ; outside of interval
        Have_Already_Shown := False
Return


ButtonOK:
    Gui, Hide
Return
I hope that helps.
After testing, replace Mod(A_Min, 2) with Mod(A_Min, 20)
neosickle
Posts: 36
Joined: 01 May 2016, 14:02

Re: need help to make reminder

03 May 2016, 20:48

Exaskryz wrote:I won't quite piece together the answer as I think this is a good exercise for you to do. But here's an example of a timer turning itself off while turning on another timer, which will later turn back on the original timer:

Code: Select all

#Persistent

SetTimer, First, 1000
return

First:
MsgBox Hello
SetTimer, First, Off ; if you delete this line, you would keep getting the Hello message box every second
SetTimer, Second, -5000 ; this timer will run once in 5 seconds
return

Second:
SetTimer, First, On ; this will turn back on the first timer
return

Esc::ExitApp ; escape key to close this
You should expect to get a message box every 6 seconds with that code, though I haven't tested it.
Thank you guys for all the help. I have now my final script. And i enjoy it alot. I am very happy learning from you guys. God bless you! Thank u thank u alot.

Here is my final script

Code: Select all

;Timer--- Timer--- Timer--- Timer--- Timer--- Timer--- Timer--- Timer--- Timer--- Timer--- Timer--- Timer--- Timer---
#NoTrayIcon
#Persistent

Gui, +AlwaysOnTop -SysMenu
Gui, Add, Text, Center, Audit na!
Gui, Add, Button, Default, OK
Gui, Color, EEAA99
Gui +LastFound
WinSet, TransColor, EEAA99
SetTimer, CheckTime, 1000 


CheckTime:

	If (A_Min = 00) OR (A_Min = 20) OR (A_Min = 40)
	
{	
		Gui, Show,,...
		SetTimer, CheckTime, Off
		SetTimer, OtherTimer, -60000
}
Return

OtherTimer:
SetTimer, CheckTime2, 60000

CheckTime2:
	If (A_Min = 00) OR (A_Min = 20) OR (A_Min = 40)
	
		Gui, Show,,...
Return

ButtonOK:
	Gui, Hide
Return

~!f3::exitapp
~!f5::suspend
~!f2::reload

neosickle
Posts: 36
Joined: 01 May 2016, 14:02

Re: need help to make reminder

03 May 2016, 20:51

wolf_II wrote:A different way to prevent the reminder from occurring several times inside the same minute would be to use a flag.
Try this:

Code: Select all

Gui +AlwaysOnTop
Gui, Add, Text, Center, Audit na!
Gui, Add, Button, Default, OK
SetTimer, CheckTime, 1000


CheckTime:
    If Mod(A_Min, 2) = 0 {          ; make testing of different intervals easier
        If Not Have_Already_Shown { ; prevent reminders from re-occuring
            Gui, Show
            Have_Already_Shown := True
        }
    } Else ; outside of interval
        Have_Already_Shown := False
Return


ButtonOK:
    Gui, Hide
Return
I hope that helps.
After testing, replace Mod(A_Min, 2) with Mod(A_Min, 20)
Thanks wolf for the effort helping me. I have now my final script above. You helped me alot for showing me a draft script. Thank you very much. My problem is now solved. Good vibes! Cheers!

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], bobkater, DRocks, Google [Bot], Gully, TAC109 and 81 guests