Results 1 to 12 of 12

Thread: Winsock + Multiple Forms = Trouble *Resolved*

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    Everywhere
    Posts
    41

    Resolved Winsock + Multiple Forms = Trouble *Resolved*

    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.

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

    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.
    Last edited by Jick; Mar 11th, 2005 at 11:03 AM.

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Winsock + Multiple Forms = Trouble

    well, wouldnt form1.winsock1.Connect

    (change connect) be what you wanted?

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    Everywhere
    Posts
    41

    Re: Winsock + Multiple Forms = Trouble

    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.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Winsock + Multiple Forms = Trouble

    Your other form could have a Public Sub or Function that you simply call in the DataArrival event.
    VB Code:
    1. Public Sub DataArrivesInThatOtherControlOnThatOtherForm(ByVal bytesTotal As Long)
    2.     'do whatever
    3. End Sub
    And call that from your other form.
    VB Code:
    1. Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
    2.     TheOtherFormName.DataArrivesInThatOtherControlOnThatOtherForm bytesTotal
    3. End Sub
    Of course you would use better names then I do

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    Everywhere
    Posts
    41

    Re: Winsock + Multiple Forms = Trouble

    I'm not sure I understand what you mean... Could you try to explain that a little better for my puny mind?

    Thanks for your help.

  6. #6
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Re: Winsock + Multiple Forms = Trouble

    VB Code:
    1. 'Form 1
    2.  
    3. private sub tcpWinsock_Dataarrival(Bytestotal as long)
    4. Dim strData as string
    5.    
    6.     tcpWinsock.getdata strData
    7.     form2.MyPublicSub strData
    8.  
    9. End sub
    10.  
    11. 'Form2
    12.  
    13. public sub MyPublicSub(WinsockData as string)
    14.  
    15.      msgbox WinsockData
    16.  
    17. end sub

    Thats what he means
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Winsock + Multiple Forms = Trouble

    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

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Winsock + Multiple Forms = Trouble

    Quote Originally Posted by Pino
    I've moved this to the Distributed Computing forum
    Do 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

  9. #9
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Re: Winsock + Multiple Forms = Trouble

    I dont agree with the relocation but there we go

    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?
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Winsock + Multiple Forms = Trouble

    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.

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Winsock + Multiple Forms = Trouble

    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.

  12. #12

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    Everywhere
    Posts
    41

    Talking Re: Winsock + Multiple Forms = Trouble

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width