Solved

Raise Event issue...

Posted on 2012-04-01
3
275 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
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 85

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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