Valhalla Legends Forums Archive | .NET Platform | [VB] 1st Error -- Making an IRC Client

AuthorMessageTime
Alendar
So I am slowly learning VB.NET and I am starting with making my own IRC client.

Right now I am getting this error:

[quote]Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.[/quote]

From this line:

[code]Private Sub wsIRC_ConnectEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles modDeclares.tpcIRC.ConnectEvent[/code]

Here is the the part where I declare the tpcIRC:

[code]Public WithEvents tpcIRC As System.Net.Sockets.TcpClient[/code]

Thank you for any assistants. As I said, I am new to VB.NET so if you have any tips for me they will be greatly appreciated.

Alendar

March 4, 2008, 2:51 AM
JoeTheOdd
Why is tcpIRC in modDeclares?

Other than that, I'm not sure. I don't know understand the syntax of VB.NET's events. If I really wanted to I could reverse some of my code with .NET Reflector, but I'm too lazy for now since someone else can probably help you.
March 4, 2008, 4:19 AM
Alendar
[quote author=Joe[x86] link=topic=17365.msg176784#msg176784 date=1204604391]
Why is tcpIRC in modDeclares?

Other than that, I'm not sure. I don't know understand the syntax of VB.NET's events. If I really wanted to I could reverse some of my code with .NET Reflector, but I'm too lazy for now since someone else can probably help you.
[/quote]

That's just where I placed it. >_>
March 4, 2008, 4:24 AM
Myndfyr
Well, System.Net.Sockets.TcpClient doesn't have a ConnectEvent event.  In fact, it doesn't have ANY events.  So, even with a WithEvents declaration, you're not going to be able to hook into the events.  Because there aren't any.

RTFM.
March 5, 2008, 4:24 AM
Imperceptus
I am working on my own IRC client at the moment.  I am just using the socket class. not tcpclient.  So far so good with that part.  This should help get you going. http://perseus.franklins.net/dnrtv/0046/parta.html

March 5, 2008, 7:06 PM
Alendar
I managed to solve my problems.
March 6, 2008, 12:38 AM
Imperceptus
Always good to share your solution, so future people that may come across this thread by searching may learn from it as well.
March 6, 2008, 3:04 AM
Alendar
I decided to go with a WinSock object and found out placing the Sub into the form helps. :p
March 6, 2008, 3:48 AM
UserLoser
sorry but i must nudge in here cause this is why this forum goes to shit:

[quote author=Joe[x86] link=topic=17365.msg176784#msg176784 date=1204604391]
Why is tcpIRC in modDeclares?

Other than that, I'm not sure. I don't know understand the syntax of VB.NET's events. If I really wanted to I could reverse some of my code with .NET Reflector, but I'm too lazy for now since someone else can probably help you.
[/quote]

useless post, if you're not sure/who cares where he declares stuff then why even say something especially if you're too lazy.

[quote author=MyndFyre[vL] link=topic=17365.msg176799#msg176799 date=1204691085]
Well, System.Net.Sockets.TcpClient doesn't have a ConnectEvent event.  In fact, it doesn't have ANY events.  So, even with a WithEvents declaration, you're not going to be able to hook into the events.  Because there aren't any.

RTFM.
[/quote]

the whole point of a forum is to ask questions.  apparently he is new, everyone makes mistakes and not everyone comprehends new terminology right away.  i never learned from reading the manual i was all hands on figuring out things my self here and there.

just voicing whats on my mind, but i liked when you were new here and used to ask how to send packets to b.net but now you boss everyone around like a dick or everyone should praise you ::)
March 6, 2008, 10:50 AM
Myndfyr
[quote author=UserLoser link=topic=17365.msg176823#msg176823 date=1204800600]
the whole point of a forum is to ask questions.  apparently he is new, everyone makes mistakes and not everyone comprehends new terminology right away.  i never learned from reading the manual i was all hands on figuring out things my self here and there.

just voicing whats on my mind, but i liked when you were new here and used to ask how to send packets to b.net but now you boss everyone around like a dick or everyone should praise you ::)
[/quote]
There's a difference between cobbling together source code that I didn't write and asking someone to explain to me why it doesn't work when it's already well-documented (which I never did) and asking about possibly obscure documentation in terms that don't jibe with what you're doing.  It's funny, because a Google search for the word "TcpClient" (nothing too terribly hard about figuring this one out) gives the documentation link as the first result.  Even when I was new I understood how to look up documentation.

It'd be one thing if he came in and said "I don't understand what a DWORD is in Visual Basic" - there's NO commonality between the Bnet data types and Visual Basic types (at least in terms of the name).  But, if you look at his source, it's clear he's got a couple different sources of code:

[code]
Handles modDeclares.tpcIRC.ConnectEvent
[/code]
modDeclares - it's clear this code is inspired by VB6.  VB.net modules don't require you to reference the module name in order to qualify the reference to the module variable.  Also, since VB.net has classes, there's not need to separate out things into a "declares" module - classes should contain the objects that they control.

Next: WithEvents/Handles -- Joe was actually correct in this case:
[quote author=UserLoser link=topic=17365.msg176823#msg176823 date=1204800600]
[quote author=Joe[x86] link=topic=17365.msg176784#msg176784 date=1204604391]
Why is tcpIRC in modDeclares?

Other than that, I'm not sure. I don't know understand the syntax of VB.NET's events. If I really wanted to I could reverse some of my code with .NET Reflector, but I'm too lazy for now since someone else can probably help you.
[/quote]
useless post, if you're not sure/who cares where he declares stuff then why even say something especially if you're too lazy.
[/quote]
WithEvents variables are only valid in the same class/type scope in which they are declared.  So, he can't just "Handles" events that are fired by an object in another class - he has to use the AddHandler/RemoveHandler semantics to get the desired behavior out of the other class, or do the preferred way and bring the variable into the class that wants to handle his events.  If he had, he would have gotten a more helpful compiler error:

[pre]error BC30590: Event 'ConnectEvent' cannot be found.[/pre]

[img]http://imgs.xkcd.com/comics/duty_calls.png[/img]
March 6, 2008, 4:55 PM
Barabajagal
Er... VB6 doesn't require you to use the module name either; I think it was for clarity.
March 6, 2008, 6:54 PM

Search