how to stop endless MsgBox due to timer? wihtout stopping timer permenantly.

Posted on 2014-12-12
Last Modified: 2014-12-12
Hi, i am making an application (Winform) using VS2010 ultimate, (VISUAL BASIC), My apologies for this is a bit long.
i tried searching all over but to no avail...

the application basically:
stores staff index information in a DB(ms Access), (fire safety training date every 6 months, patient care awareness date every year, bio-hazard safety training date every 10 months,  other dates that vary in the time they must take place....) all working fine, so far.

Objective: (works fine)
I need the application to be running in the background, i mean the task bar when minimized, i used a notifyIcon, works great, another thing, which is the point of this whole app, is that while minimized and running i placed a timer that is even displayed and counting date and time(dd-mm-yy HH:mm:ss) and so, what i want is that when the next date comes for lets say, fire_safety which is 6 months from the previous one a message box should appear even while minimized to tray to alert the user (many staff and cannot keep track just by opening every day to check!) then user presses OK then they can set a new date or leave it, does not matter so long as they are notified, anyway,

what i did (works fine):
first off, i used my own form as a message box with ok button only.
i used DateDiff, so as to check if the difference between the original or past fire safety date and the "supposedly" next one is more than 6 months then display a MsgBox "staff needs to set a date or BLAH bla..."...

well first i tried with minutes not months, to see if it is working when teh timer hits a certain value or time....
so, when the time comes, and the event is fired, a MsgBox is displayed, but as soon as i press OK, it comes up again and OK then again pops up...and so forth ..!!!????

What i tried:
im using a form as a MSgBox did not work
iused another timer for a separate evet or for the message box to close but i find that i am forced to place the msgbox in that condition i want triggered so its affected by the timer and loops.
i tried stopping the timer BEFORE the MSgBox, or disposing or myTimer.Disable=true any where in the form, but i get stuck coz one thing works and another fails...
i almost give up, i hope some one can help please.

i will attach a sample code of what is happening....and ya sorry on a side note i used (had to use a button activate the timer or enable it, dont know why but had to!)

Many thanks......

Question by:ahashash
  • 4
  • 2
  • 2
  • +1
LVL 44

Expert Comment

ID: 40495740
You have to use some sort of flag to track if the reminder has been shown (eg. bool field in a table), not show it each time the timer is hit - you have found out what happens in that case.
LVL 33

Expert Comment

ID: 40495750
when the timer was detected you have to kill the timer such to stop the timer action until you get further directive by the user. then you may place some kind of 'alert' icon to a suitable place and when the user clicked on the icon you may open a dialog or message box to ask for further action where you might create a new timer for the next period.


Author Comment

ID: 40495761
well actually i do have like a picture box that shows red or green circles to indicate if the date is past due or near or whatsoever and works fine, only thing is a messageBox that if showed then it keeps popping up because of the timer, and so if i stop the timer, then it will work one time, so i cannot restart the timer, if i did it will re-loop the popping of the msgbox... catch-22 i guess, im really stuck
i thought of the flag idea but dont really know how to implement ..
i was thinking maybe i can pause the timer do the event and resume timer, sure will raise the popping of msgbox again..
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

LVL 44

Accepted Solution

AndyAinscow earned 500 total points
ID: 40495775
>>i thought of the flag idea but dont really know how to implement ..

in the OnTimer event:

if not bIsReminderShown then
  bIsReminderShown = true
  MsgBox .....
end if

and as a 'global' variable
bool bIsReminderShown

As you talk of multiple reminder possibilities you would very likely require a number of boolean flags - set their initial values when you load the form and update the database
LVL 33

Expert Comment

ID: 40495806
you could kill the first timer and create a new one (with a different event id) which is responsible to handle the reminder and further actions. your problem is that you want to handle it with one timer what could not work beside you store information persistently somewhere in a database or inifile or registry (what you need to do anyhow if the program could be exited without an appropriate action by the user and must be resumed at next program start).

LVL 44

Expert Comment

ID: 40495819
One timer or many is irrelevant.  
If a reminder is required then that must come from some sort of permanent storage, here there is an access database with this information.
What the app is to do, if I understand correctly, is remind the user and then log their response to that reminder.
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40496252
Agreed...the flag definitely needs to be stored per "event" in the database.

Author Comment

ID: 40496738
Many thanks, i tried using a flag but did not know it should be used in teh database, so, i will try using it in the database, but just a small question though, will you please correct my sort of psuedo code here in regards to this matter;

private sub mytimer .............handles mytimer.tick
        if the whatever-flag (that is stored in the DB)- is SHOWN beside/for the fire safety_datetimepicker then
           msgbox "firesafety training is due/ or past due...."
           ' blah other blah
           exit sub
        end if
end sub

could it be somthing like that? many many thanks
sorry for the trouble.............
LVL 44

Assisted Solution

AndyAinscow earned 500 total points
ID: 40496761
Pretty much so.

ps.  Stored in the database, not used in the database.  You need to keep track somehow that the user has seen and responded to the reminder - else why bother to remind them if you don't intend tracking it.  (It won't be much use if each day they get a reminder that it is now 2, 3, 4...768...2034... days overdue).

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question