AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Syed Rizwan Muhammad Rizvi
Expertise
I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.

Experience
Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > msgbox pop-up twice

Topic: VB.NET



Expert: Syed Rizwan Muhammad Rizvi
Date: 4/18/2008
Subject: msgbox pop-up twice

Question
i put a condition on my on_leave property of my textbox. it worked out
well. but there's a slight problem, when it reached the condition that
it has to show a msgbox i have to close/click OK the msgbox twice and i
don't know why. here's the code of my textbox:

Private Sub TextBox12_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox12.Leave
      
If TextBox11.Text <> Nothing And TextBox12.Text = Nothing Then
    TextBox13.Text = CDbl(TextBox11.Text) - 0
    Exit Sub
ElseIf TextBox11.Text = Nothing And TextBox12.Text = Nothing Then
    TextBox13.Text = 0
    Exit Sub
ElseIf TextBox11.Text = Nothing And TextBox12.Text <> 0.0 Then
    MsgBox("Total Amount must not be null.", MsgBoxStyle.Exclamation)
    TextBox11.Focus()
    Exit Sub
ElseIf TextBox11.Text <> Nothing And TextBox12.Text <> Nothing Then
    TextBox13.Text = CDbl(TextBox11.Text) - CDbl(TextBox12.Text)
    Exit Sub
End If

End Sub

Answer
This might be due to the fact that after you click on OK for the first time the focus sets back to the same text box again. Please investigate that you don't any code which is executing TextBox12.Focus().

Also you can stop this by having a public flag variable. Which is set when the msgbox is displayed for the first time and next time the same event fires you simply ignore the event.


Regards,
Riz

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.