Message Box with timer
Message Box with timer
Message Box with timer
Message Box with timer
Message Box with timer
Message Box with timer Message Box with timer Message Box with timer Message Box with timer Message Box with timer Message Box with timer Message Box with timer Message Box with timer
Message Box with timer Message Box with timer
Message Box with timer
Go Back  Xtreme Visual Basic Talk > > > Message Box with timer


Reply
 
Thread Tools Display Modes
  #1  
Old 01-03-2013, 08:02 AM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default Message Box with timer


Hi I am trying to get a message box to appear once the label.text = 20 and I also want the MsgBox to close on its own without the user having to touch it, so i tried to put the code in a timer:
If Label.Text = "20" Then
MsgBox("LEVEL 2")
End IF

Any Suggestions??
Reply With Quote
  #2  
Old 01-03-2013, 09:05 AM
AtmaWeapon's Avatar
AtmaWeaponMessage Box with timer AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

You can't really do it with a normal message box. They block the calling thread, so the timer events can't run while it's displayed.

To do this, make a form that looks like a message box. It should have a timer that causes it to close itself. Display this form with the ShowDialog() method instead of Show(), and it'll be just like a message box.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 01-03-2013, 10:03 AM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

I am also having trouble with the
If Label2.Text = "20" Then
Part... Every time i run the program and the label displays the number 20, it never opens up my message box that I want to show
Help?
Reply With Quote
  #4  
Old 01-03-2013, 10:29 AM
PlausiblyDamp's Avatar
PlausiblyDampMessage Box with timer PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If you put a break point on the line in question and step through the coed in the debugger does it show the label having the correct value?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 01-03-2013, 10:33 AM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

how do you do that ?
Reply With Quote
  #6  
Old 01-03-2013, 01:32 PM
Gruff's Avatar
GruffMessage Box with timer Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Hope you do not mind AW,PD.

Qwerty,

Where in your code do you set your label.text to be 20?

I would think that just after that would be the code area from which to launch your fake messagebox.

Code:
... Label2.Text = Variable If Label2.Text = "20" then Dim dlg as New FakeMessageBox dlg.Message = "What ever you want in here" dlg.showdialog End If ...

Regarding break points and debugging. Read this link.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 01-03-2013 at 01:38 PM.
Reply With Quote
  #7  
Old 01-03-2013, 01:41 PM
PlausiblyDamp's Avatar
PlausiblyDampMessage Box with timer PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Put your cursor on the line you want to inspect in the debugger and go to the Debug menu -> Toggle Breakpoint (F9 should do the same thing). When you run your application it should break into the debugger when it hits the line you marked with a breakpoint.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #8  
Old 01-03-2013, 04:43 PM
AtmaWeapon's Avatar
AtmaWeaponMessage Box with timer AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Alternatively, post your code. I can't tell you what the problem is if I can't see the code.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #9  
Old 01-04-2013, 11:35 AM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Label2.Text = "20" Then
            Me.Hide()
            Form2.ShowDialog()

        End If
    End Sub
Reply With Quote
  #10  
Old 01-04-2013, 11:55 AM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

Quote:
Originally Posted by PlausiblyDamp View Post
Put your cursor on the line you want to inspect in the debugger and go to the Debug menu -> Toggle Breakpoint (F9 should do the same thing). When you run your application it should break into the debugger when it hits the line you marked with a breakpoint.
it says (no condition)
and the hit count is Break always (currently 0)
Reply With Quote
  #11  
Old 01-04-2013, 12:12 PM
PlausiblyDamp's Avatar
PlausiblyDampMessage Box with timer PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Quote:
Originally Posted by qwerty123vb View Post
it says (no condition)
and the hit count is Break always (currently 0)
So when you run the application from Visual Studio does it stop on the line with the breakpoint? If so you can inspect the values of variables etc at runtime and see if things contain the values you expect. This is all covered in the link Gruff give back in post #6
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #12  
Old 01-04-2013, 01:11 PM
AtmaWeapon's Avatar
AtmaWeaponMessage Box with timer AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

That's the Load event. It's only going to be raised once, when the form loads. So your If statement is only going to execute if the text box contains EXACTLY the string "20" (no spaces) when the form loads. I sort of expected to see your condition in a timer's Tick event handler.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #13  
Old 01-04-2013, 10:56 PM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

Quote:
Originally Posted by AtmaWeapon View Post
That's the Load event. It's only going to be raised once, when the form loads. So your If statement is only going to execute if the text box contains EXACTLY the string "20" (no spaces) when the form loads. I sort of expected to see your condition in a timer's Tick event handler.
so what do you suggest i do because im not quite sure what you mean
Reply With Quote
  #14  
Old 01-04-2013, 11:38 PM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

Quote:
Originally Posted by PlausiblyDamp View Post
So when you run the application from Visual Studio does it stop on the line with the breakpoint? If so you can inspect the values of variables etc at runtime and see if things contain the values you expect. This is all covered in the link Gruff give back in post #6
Well what happens is that when i highlight the line
Code:
If Label2.Text = "20" Then
it skips over the code that displays the fake message box
but when i highlight the code
Code:
me.hide()
it works fine and the fake message box appears
Reply With Quote
  #15  
Old 01-05-2013, 10:02 AM
AtmaWeapon's Avatar
AtmaWeaponMessage Box with timer AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Quote:
Originally Posted by qwerty123vb View Post
so what do you suggest i do because im not quite sure what you mean
Put the code in the timer's tick handler. Are you familiar with that?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #16  
Old 01-05-2013, 11:47 AM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

Quote:
Originally Posted by AtmaWeapon View Post
Put the code in the timer's tick handler. Are you familiar with that?
you mean make a sub for a timer and put my code in there??
Would that fix the problem??
Reply With Quote
  #17  
Old 01-05-2013, 03:58 PM
passel's Avatar
passelMessage Box with timer passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

Quote:
Originally Posted by qwerty123vb View Post
..., so i tried to put the code in a timer:
If Label.Text = "20" Then
MsgBox("LEVEL 2")
End IF

Any Suggestions??
From the first line of your first post.
What did you mean you "tried to put the code in a timer"?
You might make better progress if rather than just trying to jump into the middle of trying to code some concept you have, you learn the capabilities of the tool you're going to use first, in an organized manner, through some tutorials, or perhaps better, a book.
I still find it hard to believe the number of people who want to write a program, but apparently without wanting to learn how to write a program.
I don't believe this is the best forum for trying to learn to program from scratch, but you are welcome to continue if you believe you are getting what you need from it.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #18  
Old 01-05-2013, 04:33 PM
AtmaWeapon's Avatar
AtmaWeaponMessage Box with timer AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Yes, if "make this code happen in response to a timer event" is over your head, you really need to spend a couple of hours with your nose in a book. It sounds mean and condescending, but there's a certain number of prerequisites that are really difficult to explain in a forum post. It's like if you were asking questions about derivatives of functions but first needed an explanation of addition.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Message Box with timer
Message Box with timer
Message Box with timer Message Box with timer
Message Box with timer
Message Box with timer
Message Box with timer Message Box with timer Message Box with timer Message Box with timer Message Box with timer Message Box with timer Message Box with timer
Message Box with timer
Message Box with timer
 
Message Box with timer
Message Box with timer
 
-->