Need Help w/ WithEvent Errors Please

Need help with coding withevent variable into browser code asap please

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 6028 Views - Last Post: 27 July 2008 - 04:49 PM Rate Topic: -----

#1 sbh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-July 08

Need Help w/ WithEvent Errors Please

Post icon  Posted 27 July 2008 - 12:44 PM

I was wandering if I could get some help with this code I have. I am using VB Express 2008 and I get 4 errors, 3 of them being something about "Handles clause requires WithEvents variable defined in containing type or one of it's base types."
First if someone could explain a little bit about what that means to me. But most importantly I need to know how to code those withevents variables into the 3 different sections of the part of the code that needs it. I am pretty new so I don't know much really at all.

Here are the bits of code that need the variables. I've underlined the parts which VB Express underlines and then when you put the cursor over it it shows the error. Also all their errors except for one is this:

Quote

Handles clause requires a WithEvents variable defined in the containing type or one of its base types.


The other error is PCPrint is not defined which I kind of understand but have no idea how to fix, so if someone could help me with that one after these WithEvents things are resolved that would be great!

First bit of code:

Private Sub NewWindowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles [u]NewWindowToolStripMenuItem[/u].Click
		Dim f2 As New Form
		WebBrowser1.Navigate("http://www.sbhweb.co.nr")
		f2.Show()
	End Sub


Second bit of code:

Private Sub printToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles [u]printToolStripMenuItem[/u].Click
		Dim printer As New [u]PCPrint[/u]()
		printer.PrinterFont = New Font("Verdana", 10)
		printer.TextToPrint = TextBox1.Text
		printer.Print()
	End Sub


Third error is like I said PCPrint is not defined, and it is the underlined word in the section of code above.

Fourth and final bit of code:

Private Sub SourceToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles [u]SourceToolStripMenuItem1[/u].Click
		Me.Show()
	End Sub


I'm sorry if this is a lot but I'd really like to get these errors solved. I don't understand it and would really like to if someone could teach me. I'd like help as fast as anyone could help me and I don't care who does. Sorry if it's a lot!
If you need anything else let me know. :) :ph34r: :D

Is This A Good Question/Topic? 0
  • +

Replies To: Need Help w/ WithEvent Errors Please

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 01:07 PM

Somewhere in the your you'll have a statement similar to this
    Dim newf As New Form


and something like this is throw this error
"Handles clause requires WithEvents variable defined in containing type or one of it's base types."
   Private Sub newf _Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newf.Click

    End Sub



To get it to work
    Dim WithEvents newf As New Form


Was This Post Helpful? 0
  • +
  • -

#3 sbh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-July 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 01:15 PM

K did that now it says something like:

Quote

'WithEvents' is not valid on a local variable declaration.


I did that to the first one, now it says:

Private Sub NewWindowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewWindowToolStripMenuItem.Click
		Dim WithEvents newf As New Form
		WebBrowser1.Navigate("http://www.sbhweb.co.nr")
		f2.Show()
	End Sub

This post has been edited by sbh: 27 July 2008 - 01:16 PM

Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 01:21 PM

Quote

'WithEvents' is not valid on a local variable declaration.


Put it outside then. :P

Dim WithEvents f2 As New Form
Private Sub NewWindowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
		Handles NewWindowToolStripMenuItem.Click
		WebBrowser1.Navigate("http://www.sbhweb.co.nr")
		f2.Show()
	End Sub



Scope of variables tutorial

This post has been edited by AdamSpeight2008: 27 July 2008 - 01:23 PM

Was This Post Helpful? 0
  • +
  • -

#5 sbh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-July 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 01:26 PM

What do you mean the program says it's not valid or whatever, what do you mean by put it outside, put what outside??
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 01:32 PM

' Move to here from here.
Dim WithEvents f2 As New Form 
Private Sub NewWindowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
		Handles NewWindowToolStripMenuItem.Click
'From Here
		WebBrowser1.Navigate("http://www.sbhweb.co.nr")
		f2.Show()
	End Sub



Scope of variables tutorial
Was This Post Helpful? 0
  • +
  • -

#7 indrora  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 100
  • Joined: 25-July 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 01:52 PM

I think what Adam is trying to say is that you have to modify the declaration of the form slightly.

VB has a slight twist to dealing with variables. this is perfectly valid:
 public static WithEvents form1 as new form = new windows.forms.form()

VB allows you to specifiy "modifiers" to variables -- public, private, etc.
WithEvents is one that cannot stand alone. think of it this way (in RegEx terms...)
(public|private|shared) (static?) dim WithEvents? NAME (as kind)? (= expression)?

I may have that messed up beyond all repair but what i'm trying to say is that WithEvents is a modifier to "dim" which can be replaced with any other forms of instantiation.
Was This Post Helpful? 0
  • +
  • -

#8 sbh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-July 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 01:57 PM

K all it did was separate it like it's another sub and it still says it needs the with events variable. (This is on the first bit of code still)

K let me try your way then indora
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 01:58 PM

I'm trying to say where and how you define an object (Eg f2) affects how and where from it can be used.
This is the reason why I included a link to the tutorial.
Was This Post Helpful? 0
  • +
  • -

#10 sbh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-July 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 02:03 PM

All right I copied and pasted the one indora gave me above the first bit of code.
It now says that:

'Static' is not valid on a WithEvents declaration.

and:

End of Statement expected
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 02:04 PM

You also need to it for other controls you've created this way as well.
Eg
NewWindowToolStripMenuItem
printToolStripMenuItem
SourceToolStripMenuItem1
Was This Post Helpful? 0
  • +
  • -

#12 sbh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-July 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 02:07 PM

I need to do that for what you said or what indora said?
Was This Post Helpful? 0
  • +
  • -

#13 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 02:09 PM

View Postsbh, on 27 Jul, 2008 - 10:07 PM, said:

I need to do that for what you said or what indora said?

I in an Ali G voice
Was This Post Helpful? 0
  • +
  • -

#14 sbh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-July 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 02:15 PM

Huh?

k I'm confused

K well am I supposed to put the one indora gave me inside, because if I do it takes away the error that says the static thing is invaild, and leaves me with the end of statement expected. So what would I do with it now?

This post has been edited by sbh: 27 July 2008 - 02:17 PM

Was This Post Helpful? 0
  • +
  • -

#15 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Need Help w/ WithEvent Errors Please

Posted 27 July 2008 - 02:20 PM

If possible post the full code not just the code section causing the error.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2