Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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..
Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

LVL 44

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 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 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 44

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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

722 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