Solved

Raise Event issue...

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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