Solved

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

Posted on 2014-12-12
9
322 Views
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..."...

THE PROBLEM:
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......

myTimer-code.txt
0
Comment
Question by:ahashash
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
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.
0
 
LVL 32

Expert Comment

by:sarabande
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.

Sara
0
 

Author Comment

by:ahashash
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..
0
 
LVL 44

Accepted Solution

by:
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
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 32

Expert Comment

by:sarabande
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).

Sara
0
 
LVL 44

Expert Comment

by:AndyAinscow
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.
0
 
LVL 85

Expert Comment

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

Author Comment

by:ahashash
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
        else
           exit sub
        end if
end sub

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

Assisted Solution

by:AndyAinscow
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).
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now