Solved

WithEvents in VB 2005

Posted on 2009-06-29
3
439 Views
Last Modified: 2012-05-07
Any suggestions why I get the following error: "Handles clause requires a WithEvents variable defined in the containing type or one of its base types"? It occurs on the "emlbutton" of "handles emailbutton.click." I'm a newbie so maybe this is just something simple I'm overlooking...

Public Shared Sub emlbutton_click(ByVal subject As String, ByVal messageBody As String, _

        ByVal fromAddress As String, ByVal toAddress As String, ByVal ccAddress As String) Handles emlbutton.click

Open in new window

0
Comment
Question by:premiertechconsulting
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 24740811
"Handles" requires a corresponding declaration using the "WithEvents" keyword.  For controls added at design-time in the IDE, this is done for you and placed into a normally hidden file.  In the Project Pane, click on the "Show all files" button and then double click on the xxx.designer.vb file for your form.

You should have something like this in there:
(don't modify this file manually!)

    Friend WithEvents Button1 As System.Windows.Forms.Button

The error is telling you that it can't find the matching WithEvents declaration for "emlbutton" in the designer file (or the current class code).

So somehow your designer file has become corrupt or out of "sync" with your code, or you have a locally declared variable that needs "WithEvents" added to it.
0
 

Author Comment

by:premiertechconsulting
ID: 24746158
Idle Mind,
Your are correct. I tried to to view my file in design time but VB is telling me I have errors (however, I can still view in a browser). So let's back track a little...
The error is "Cannot switch views: Validation (XHTML 1.0 Transitional): Element 'link' cannot be nested within element 'html'. " I must admit that I cheated a little in that I copied and pasted from a html view source file as that was all I had access to at the time and I need the css style sheet.  Here are the "links" that are causing the problem. I guess I don't understand why the links cannot be nested within html when the entire page is html.


<link rel="stylesheet" href="http://www.mulliganagain.com/wp-content/themes/default/style.css" type="text/css" media="screen" />

<link rel="alternate" type="application/rss+xml" title="&#8220;I&#8217;ll take my Mulligan now!&#8221; RSS Feed" href="http://www.mulliganagain.com/?feed=rss2" />

<link rel="alternate" type="application/atom+xml" title="&#8220;I&#8217;ll take my Mulligan now!&#8221; Atom Feed" href="http://www.mulliganagain.com/?feed=atom" />

<link rel="pingback" href="http://www.mulliganagain.com/xmlrpc.php" />
 

<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.mulliganagain.com/xmlrpc.php?rsd" />

<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.mulliganagain.com/wp-includes/wlwmanifest.xml" /> 

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24746326
I'm glad we've narrowed down the problem...but unfortunately I have NO clue when it comes to web programming.  I simply focused on the core WithEvents/Handles error....   =(
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now