Go Premium for a chance to win a PS4. Enter to Win


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

Posted on 2014-12-12
Medium Priority
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 45

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 35

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..
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 45

Accepted Solution

AndyAinscow earned 2000 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 35

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 45

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 86

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 45

Assisted Solution

AndyAinscow earned 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

824 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