Solved

Raise Event issue...

Posted on 2012-04-01
3
284 Views
Last Modified: 2012-04-01
To see the problem, consider following the following steps:

1.      Click “Default Values” button
2.      Click on “Create Car” button.
3.      Click on “Drive” button.
4.      Enter 210 miles. Click ok.
5.      After 210 miles gas level drops down to 3 miles.
6.      There is a raise event to inform the user to pump gas (if less or 5 gal.)

The problem is that the warning comes up two times.

Question: How can I correct it so that the low gas warning will come up only once?

Thank you.
CarClass.txt
FormCode.txt
frmMyCar.vb
0
Comment
Question by:Mike Eghtebas
[X]
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
3 Comments
 
LVL 39

Accepted Solution

by:
appari earned 400 total points
ID: 37794506
change this part in your frmCar1.vb code

Sub LowGasMessage() Handles myCar.LowGasLevel
        MessageBox.Show("Pump gas, after driving, you will have only 5 gallons of gas left.", "Low Gas Warnning...", _
                        MessageBoxButtons.OK, MessageBoxIcon.Warning)
    End Sub

TO, no need to write handles ....


Sub LowGasMessage()
        MessageBox.Show("Pump gas, after driving, you will have only 5 gallons of gas left.", "Low Gas Warnning...", _
                        MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Sub
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
ID: 37794520
You have "myCar" declared as WithEvents and correctly paired with a Handles clause to trap the LowGasLevel event.

Therefore you do NOT need AddHandler and RemoveHandler at lines #106 and #108.  Get rid of both of those.
0
 
LVL 34

Author Closing Comment

by:Mike Eghtebas
ID: 37794547
Thank you
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get sourcecode path 14 63
Need help with another query 10 54
Convert a string to date 4 40
How to send the email using C# with embedded HTML TABLE 3 22
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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