473,513 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

message box and time question?

Hello All,
Is it possible in vb 08 to set a message box to pop up when you click a
button and have a cod that sets a time in seconds so that lets say after 5
sec. the message box closes by itself when the counter reach 0 sec. ?

Thanks for all of your help...
Oct 2 '08 #1
9 8399
On Oct 2, 11:06*am, karim <ka...@discussions.microsoft.comwrote:
Hello All,
Is it possible in vb 08 to set a message box to pop up when you click a
button and have a cod that sets a time in seconds so that lets say after 5
sec. the message box closes by itself when the counter reach 0 sec. ?

Thanks for all of your help...
Karim,
Closing messagebox automatically can be done by sending ENTER key to
the application within a Timer's tick event sub, so place a Timer
control on your form and set its interval property to "5000" (5
seconds). Then place a button onto form to show messagebox and to run
timer as follows:

'------------------------
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
MsgBox("Hello World")
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
SendKeys.Send("{ENTER}")
Timer1.Enabled = False
End Sub

End Class
'-------------------------------
Hope this helps,

Onur Güzel
Oct 2 '08 #2
Thank you very much. works great.
and one other thing if you don't mind. it's not really a big deal, but would
you be able to show the time counting down on the message box?

"kimiraikkonen" wrote:
On Oct 2, 11:06 am, karim <ka...@discussions.microsoft.comwrote:
Hello All,
Is it possible in vb 08 to set a message box to pop up when you click a
button and have a cod that sets a time in seconds so that lets say after 5
sec. the message box closes by itself when the counter reach 0 sec. ?

Thanks for all of your help...

Karim,
Closing messagebox automatically can be done by sending ENTER key to
the application within a Timer's tick event sub, so place a Timer
control on your form and set its interval property to "5000" (5
seconds). Then place a button onto form to show messagebox and to run
timer as follows:

'------------------------
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
MsgBox("Hello World")
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
SendKeys.Send("{ENTER}")
Timer1.Enabled = False
End Sub

End Class
'-------------------------------
Hope this helps,

Onur Güzel
Oct 2 '08 #3
Hello karim,
>Closing messagebox automatically can be done by sending ENTER key to
the application within a Timer's tick event sub, so place a Timer
control on your form and set its interval property to "5000" (5
seconds). Then place a button onto form to show messagebox and to run
timer as follows:

'------------------------
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
MsgBox("Hello World")
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
SendKeys.Send("{ENTER}")
Timer1.Enabled = False
End Sub

End Class
'-------------------------------
This method works, but it has one catch: Let's say that you have a
Yes/No message box and the user is just moving the mouse pointer to
"No", but as the 5 seconds just expired "Yes" will be automatically
executed. I would suggest to use this only with "OkOnly" style message
boxes.

On the other hand I wonder: If a message box can be closed automatically
it seems that the information it shows is not important. Why then
display it in the first place?

Best regards,

Martin
Oct 2 '08 #4
On Oct 2, 4:06*am, karim <ka...@discussions.microsoft.comwrote:
Hello All,
Is it possible in vb 08 to set a message box to pop up when you click a
button and have a cod that sets a time in seconds so that lets say after 5
sec. the message box closes by itself when the counter reach 0 sec. ?

Thanks for all of your help...
While using SendKeys to close the message box will work, I would
recommend you create your own form to display. Creating MessageBox
type form should just take a matter of minutes, and once it's done,
expanding it to include the countdown functionality is as simple as
adding a label and a timer control.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Oct 2 '08 #5

"Martin H." <hk***@gmx.netkirjoitti viestissä news:48********@127.0.0.1...
This method works, but it has one catch: Let's say that you have a Yes/No
message box and the user is just moving the mouse pointer to "No", but as
the 5 seconds just expired "Yes" will be automatically executed. I would
suggest to use this only with "OkOnly" style message boxes.
And what if the message box loses it's focus during that five seconds. Then
some other application will receive that ENTER-key and that application
might just be asking "Do you really want to delete all files?"

So, what I'm trying to say is that if SendKeys is used you should check that
the message box is really focused.

-Teemu

Oct 2 '08 #6
On Oct 2, 7:31*am, "Teemu" <tsir...@hotmail.comwrote:
"Martin H." <hk...@gmx.netkirjoitti viestissnews:48********@127.0.0.1....
This method works, but it has one catch: Let's say that you have a Yes/No
message box and the user is just moving the mouse pointer to "No", but as
the 5 seconds just expired "Yes" will be automatically executed. I would
suggest to use this only with "OkOnly" style message boxes.

And what if the message box loses it's focus during that five seconds. Then
some other application will receive that ENTER-key and that application
might just be asking "Do you really want to delete all files?"

So, what I'm trying to say is that if SendKeys is used you should check that
the message box is really focused.

*-Teemu
Yep - this is one of the many reason to just roll your own form. It's
much safer to wire the functionality into a new form than hack the
MessageBox with SendKeys.

Besides, how on earth could you test that the MessageBox was closed?

(To the OP) You are unit testing aren't you?

:-)

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/

Oct 2 '08 #7
On Oct 2, 2:31*pm, "Teemu" <tsir...@hotmail.comwrote:
"Martin H." <hk...@gmx.netkirjoitti viestissänews:48********@127.0.0.1...
This method works, but it has one catch: Let's say that you have a Yes/No
message box and the user is just moving the mouse pointer to "No", but as
the 5 seconds just expired "Yes" will be automatically executed. I would
suggest to use this only with "OkOnly" style message boxes.

And what if the message box loses it's focus during that five seconds. Then
some other application will receive that ENTER-key and that application
might just be asking "Do you really want to delete all files?"

So, what I'm trying to say is that if SendKeys is used you should check that
the message box is really focused.

*-Teemu
That's somehow right, SendKeys solution is valid during the messagebox
has the focus, though 5 seconds can be considered short, you can't
know when message box can lose focus.

Plus, Sending ENTER key using SendKeys can close messagebox if it's a
OkOnly (simple) messagebox as Martin stated, in that case, developer
can consider sending ESCAPE or other keys to get other MessageBox
result rather than OK.

Onur Güzel
Oct 2 '08 #8
On Oct 2, 12:17*pm, karim <ka...@discussions.microsoft.comwrote:
Thank you very much. works great.
and one other thing if you don't mind. it's not really a big deal, but would
you be able to show the time counting down on the message box?

"kimiraikkonen" wrote:
On Oct 2, 11:06 am, karim <ka...@discussions.microsoft.comwrote:
Hello All,
Is it possible in vb 08 to set a message box to pop up when you clicka
button and have a cod that sets a time in seconds so that lets say after 5
sec. the message box closes by itself when the counter reach 0 sec. ?
Thanks for all of your help...
Karim,
Closing messagebox automatically can be done by sending ENTER key to
the application within a Timer's tick event sub, so place a Timer
control on your form and set its interval property to "5000" (5
seconds). Then place a button onto form to show messagebox and to run
timer as follows:
'------------------------
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
MsgBox("Hello World")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
SendKeys.Send("{ENTER}")
Timer1.Enabled = False
End Sub
End Class
'-------------------------------
Hope this helps,
Onur Güzel- Hide quoted text -

- Show quoted text -
If you're meaning showing remaing seconds in messagebox in real-time,
as far as i know it's not possible to update MessageBox content,
however if you implement a small messagebox-like form, then you'll be
simply able to show remaining seconds on your form using a Timer
control with 1 seconds (1000 ms) interval.

'-------------------------------------
' Assuming you've added a small form and a timer on it
Public Class Form1
Dim remaining As Integer = 5
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick

' Eg: Show remaining time in a Label
remaining -=1
Label1.Text = remaining

If remaining = 0 Then
Timer1.Enabled = False
' When time is up, close current form
Me.Close()

End Sub
'----------------------------------

Hope this helps,

Onur Güzel

Oct 2 '08 #9
Hi Onur,

I always forget this one and start making my own dialog for this kind of
purposes.

Thank you for reminding me.

Cor

"kimiraikkonen" <ki*************@gmail.comschreef in bericht
news:e7**********************************@l76g2000 hse.googlegroups.com...
On Oct 2, 11:06 am, karim <ka...@discussions.microsoft.comwrote:
Hello All,
Is it possible in vb 08 to set a message box to pop up when you click a
button and have a cod that sets a time in seconds so that lets say after 5
sec. the message box closes by itself when the counter reach 0 sec. ?

Thanks for all of your help...
Karim,
Closing messagebox automatically can be done by sending ENTER key to
the application within a Timer's tick event sub, so place a Timer
control on your form and set its interval property to "5000" (5
seconds). Then place a button onto form to show messagebox and to run
timer as follows:

'------------------------
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
MsgBox("Hello World")
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
SendKeys.Send("{ENTER}")
Timer1.Enabled = False
End Sub

End Class
'-------------------------------
Hope this helps,

Onur Güzel

Oct 2 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3696
by: blue | last post by:
We are using a java codebase which writes data to a SQL Server 2000 database using the JTurbo (3.0) JDBC driver. We are finding that a record update takes longer and longer as the table grows. For example, when the table has ~200,000 records, the update will be around 1 second. Once table is up to ~800,000 records, an update starts taking...
5
2284
by: Gord | last post by:
Many scripts and calendars call client side system time in order to make presentations. However, the client's time may be improperly set, if set at all, and/or the relevant time may be from another time zone. It would be of great value if the time of some central source could be drawn, in the form of a ".js" file, into the script to avoid...
2
1863
by: Gvs | last post by:
Hi, I'm currently trying to pass messages into a queue. This all works fine, however, i'm trying to my program to stop sending messages to the queue when it reaches an upper threshold. At present this threshold is the number of chairs in a waiting room. This is an int represented by nChairs. So i want to compare this to the number of...
11
1330
by: Phill | last post by:
I'm new to C# and so far I'm pretty happy with the language and the design behind it. My only real concern is about performance. I wanted to ask a question about how a program you build in Visual studio gets handled. After it is built you have what looks like an normal win32 exe. And at least part of that code must be because it runs. Now...
1
1287
by: Charles Shao | last post by:
Message Queue Question: I'm trying to make a demo for MSMQ. I send a message(string) on client and try to receive it in a daemon(Windows service). Now, I get a problem: 1. When I start the service in services manager, The start event will be time out. but in fact, the service is running and in loop "for". What can I to for this problem.
9
1386
by: Zach | last post by:
I would like to express the time with the time continually changing. I can get it to show once, but then it stays that way, using a loop jams. Is there a way to do this?
2
981
by: JoeP | last post by:
Hi all, I have the below code for sending e-mail: oMailMessage.Subject = Now.Date.ToString() & " " & Now.DayOfWeek.ToString() & " XYZ" From some reason the time portion of the Date shows all the time the 12.00:00 AM instead of the real time. Any idea? Thanks,
7
1986
by: JamesG | last post by:
Hi, I need to convert the current time to the format "hh:mm:ss" and date to the format "yyyy-MM-dd". The result of both conversions needs to be of System.DateTime format. I've tried using DateTime.ParseExact and DateTimeFormatInfo but failed, most examples I see convert the final result to a string... I dont want that!
39
2509
by: jaad | last post by:
There are literally thousands and thousands of entry about this subject but still after 6 years of looking and researching I haven't found a simple answer to a really simple question: I have two fields: , format as am and pm and a mask that validate the field as a short time mask. What I need to know is how to calculate the difference in...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.