PDA

Click to See Complete Forum and Search --> : Winsock + Multiple Forms = Trouble *Resolved*


Jick
Mar 10th, 2005, 08:57 PM
Hello all!
This is my first post here. I've been a member of the community for a couple days now but I've been finding pretty much everything I need through searching the forums so I haven't had a need to post until now. I'm new to Visual Basic. I just installed and started using Visual Basic 6.0 about a week ago and I've been having loads of fun learning and experimenting.

I'm currently working on making a chatting program with the help of Winsock. It's all been going pretty good so far but I've hit a road block. I've searched all over the forums and on Google as well. I have found nothing related to my particular situation thus far.

Anyway, I'll stop boring you all now and get to my question. :p

I think my question will be easy for you VB Veterans but for me it's a mind-blower. :eek2:

My question is, how can I continue a Winsock connection started in one form on another form? Right now I have two forms. One is called frmLogin and the other is called frmMain. As you can probably guess by the name, frmLogin comes up first when the program first starts. It requests a username and IP address from the user. Then it attempts to connect. I use this as validation. If it can connect then they are let through to frmMain but if it can't connect then they receive an error asking them to try again. So far so good. Everything that I have said so far works how it should.

Now for the problem area. If they supply correct info then they are transfered to frmMain which is the actual chat program. Now for the life of me, I can't figure out how to transfer that connection to frmMain where it is needed. I need it so it connects on frmLogin and they can chat on frmMain.

How can I transfer that connection so it can be used on frmMain? Is it possible? Thanks for any and all help. :D

|2eM!x
Mar 10th, 2005, 09:00 PM
well, wouldnt form1.winsock1.Connect

(change connect) be what you wanted?

Jick
Mar 10th, 2005, 09:20 PM
Well that works for the most part but it doesn't work when it comes to dealing with "DataArrival". The "DataArrival" function looks like "Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)" and I have found no way to make it so that is linked to the Winsock on the other form.

Joacim Andersson
Mar 10th, 2005, 10:00 PM
Your other form could have a Public Sub or Function that you simply call in the DataArrival event.Public Sub DataArrivesInThatOtherControlOnThatOtherForm(ByVal bytesTotal As Long)
'do whatever
End Sub And call that from your other form.Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
TheOtherFormName.DataArrivesInThatOtherControlOnThatOtherForm bytesTotal
End Sub Of course you would use better names then I do :)

Jick
Mar 10th, 2005, 10:26 PM
I'm not sure I understand what you mean... Could you try to explain that a little better for my puny mind? :p

Thanks for your help. :D

BodwadUK
Mar 11th, 2005, 02:25 AM
'Form 1

private sub tcpWinsock_Dataarrival(Bytestotal as long)
Dim strData as string

tcpWinsock.getdata strData
form2.MyPublicSub strData

End sub

'Form2

public sub MyPublicSub(WinsockData as string)

msgbox WinsockData

end sub




Thats what he means :)

Pino
Mar 11th, 2005, 04:43 AM
I've moved this to the Distributed Computing forum,

Ok the methods suggested above would all work, but how about not having any winsocks on the login page?

What i would do is have the connection on frmMain, you can call the connection from the logIn page using frmMain.Winsock.connect (etc) and the dataArrival can be handled on frmMain too.

You can use a prefix to distinguish between chat messages and logIn messages.

I hope this helps, if you are nuse about anything please post back :)

Pino

Joacim Andersson
Mar 11th, 2005, 04:50 AM
I've moved this to the Distributed Computing forumDo that with all questions regarding Winsock and the General VB Forum will be cut to half its size :) This isn't even an n-tier question, so I for one doesn't understand why you moved it here ;)

BodwadUK
Mar 11th, 2005, 04:58 AM
I dont agree with the relocation but there we go :afrog:

You can do either it doesnt matter. The advantage with Pino's idea is all code will be in one place for the winsock.

What does "nuse" mean? :ehh:

Pino
Mar 11th, 2005, 08:22 AM
This forum is for Network questions as well including the winsock control. And hence this post belongs here. :)

If you have any further doubts please PM me.

Joacim Andersson
Mar 11th, 2005, 08:38 AM
OK, but the question wasn't really about the Winsock control, it's more a multi form question. The question could just as well been related to almost any other control.

Jick
Mar 11th, 2005, 10:02 AM
Thank you all for your replies. I found all the information very useful.

I ended up using Pino's method. I'm not sure why I didn't think about that before but it does work. Thank you Pino and thank you to everyone else who helped. :D