Results 1 to 8 of 8

Thread: [RESOLVED] How do I input an IP address into a chat program?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    36

    Resolved [RESOLVED] How do I input an IP address into a chat program?

    Greetings- I am really new to VB(started yesterday) and have spent the last few hours trying to solve a problem.

    Instead of "hard coding" an IP address into the client, I want the user to be able to type it into a text box and then use that as the variable. If I could get a lil nudge in the right direction I would be very grateful. Below is some of the code and hopefully you will understand what I am trying to do. Also, I found a way to do it with an input command, but I want to be able to type the IP into a text box and then use that as the variable. Does that make sense to anyone?


    insertIP = (insertIP.Text)
    If insertIP <> "" Then
    If Winsock1.State <> sckClosed Then Winsock1.Close
    Winsock1.RemoteHost = insertIP.Text
    Winsock1.RemotePort = 5000
    Winsock1.LocalPort = 0
    Winsock1.Connect
    End If

    Thanks for any and all replies.

    Bry

    EDIT-See bottom post for correct code.
    Last edited by BryanW; Jun 30th, 2006 at 12:56 PM.

  2. #2
    Lively Member GoldEagle's Avatar
    Join Date
    Feb 2006
    Location
    Canada
    Posts
    82

    Re: How do I input an IP address into a chat program?

    Instead of using the Winsock1.RemoteHost use Winsock1.RemoteHostIP.

    That should get it started.
    Last edited by GoldEagle; Jun 30th, 2006 at 11:56 AM.
    If you found my post in anyway helpful please rate it.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How do I input an IP address into a chat program?

    Welcome to the forums.

    Declaring a variable and then storing the contents of a textbox or something into the variable is done nearly every program written. Just do something like
    VB Code:
    1. Dim strIP As String
    2. strIP = txtIPAddress.Text
    Then us strIP for whatever you want.

  4. #4
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    Re: How do I input an IP address into a chat program?

    Not even necessary. If I remember back to the winsock days, you could use the connect command like this
    Winsock.connect IPGOESHERE, PORTGOESHERE

    But I haven't touched VB in a while, but try it out. What's really the point of storing the IP in winsock if you already have it in a text box. Am I right?

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    36

    Re: How do I input an IP address into a chat program?

    Thanks for the fast replies. This seems like it should be so easy to do, I can get the program to work when I hard code the IP in, but not when I try to use a variable. Please take a gander at what I have so far and let me know what I am doing wrong. I am still in the copy others work and try to figure out what they are doing. It's prob lots slower than buying a course on VB but all i have is time. Thnx again.

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.  Dim strIP As String
    4.        
    5.          strIP = txtIPAddress.Text
    6.          If insertIP <> "" Then
    7.          If Winsock1.State <> sckClosed Then Winsock1.Close
    8.             Winsock1.RemoteHostIP = strIP
    9.             Winsock1.RemotePort = 5000
    10.             Winsock1.LocalPort = 0
    11.             Winsock1.Connect
    12.          End If
    13.  
    14.  
    15. End Sub
    16.  
    17. Private Sub Commandsend_Click()
    18.  
    19. If Winsock1.State = sckConnected Then
    20.     Winsock1.SendData (txtname) & ": " & (txtchat)
    21.     DoEvents
    22.     txtmain.Text = txtmain.Text & vbCrLf & (txtname) & ": " & (txtchat)
    23.     txtmain.SelStart = Len(txtmain.Text)
    24. End If
    25.  
    26. txtchat = ""
    27.    
    28. End Sub
    29.  
    30. Private Sub Winsock1_Connect()
    31.     MsgBox "Connected"
    32. End Sub
    33.  
    34. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    35.     Dim chatdata As String
    36.     Winsock1.GetData chatdata
    37.     txtmain = (txtmain) & vbCrLf & chatdata
    38.         txtmain.SelStart = Len(txtmain.Text)
    39.    
    40.    
    41. End Sub

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How do I input an IP address into a chat program?

    Try this
    VB Code:
    1. Dim strIP As String
    2.        
    3.          strIP = txtIPAddress.Text
    4.          If insertIP <> "" Then
    5.          If Winsock1.State <> sckClosed Then Winsock1.Close
    6.             Winsock1.RemoteHostIP = strIP
    7.             Msgbox strIP
    8.             Winsock1.RemotePort = 5000
    9.             Winsock1.LocalPort = 0
    10.             Winsock1.Connect
    11.          End If
    Is the IP address that you want in the message box?

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    36

    Re: How do I input an IP address into a chat program?

    And it's working! Here's the code that worked. Thank you very much guys.



    VB Code:
    1. Private Sub Command1_Click()
    2.  Dim strIP As String
    3.        
    4.          strIP = txtIPAddress.Text
    5.          If strIP <> "" Then
    6.          If Winsock1.State <> sckClosed Then Winsock1.Close
    7.             Winsock1.RemoteHost = strIP
    8.             Winsock1.RemotePort = 5000
    9.             Winsock1.LocalPort = 0
    10.             Winsock1.Connect
    11.          End If
    12.  
    13. End Sub
    14.  
    15. Private Sub Commandsend_Click()
    16.  
    17. If Winsock1.State = sckConnected Then
    18.     Winsock1.SendData (txtname) & ": " & (txtchat)
    19.     DoEvents
    20.     txtmain.Text = txtmain.Text & vbCrLf & (txtname) & ": " & (txtchat)
    21.     txtmain.SelStart = Len(txtmain.Text)
    22. End If
    23.  
    24. txtchat = ""
    25.    
    26. End Sub
    27.  
    28.  
    29.  
    30. Private Sub Winsock1_Connect()
    31.     MsgBox "Connected"
    32. End Sub
    33.  
    34. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    35.     Dim luvlydata As String
    36.     Winsock1.GetData luvlydata
    37.     txtmain = (txtmain) & vbCrLf & luvlydata
    38.         txtmain.SelStart = Len(txtmain.Text)
    39.    
    40.    
    41. End Sub
    Last edited by BryanW; Jun 30th, 2006 at 12:53 PM.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How do I input an IP address into a chat program?

    Quote Originally Posted by BryanW
    I got it to work thank you very much!
    Glad to hear it.

    If you consider this resolved, would you please pull down the Thread Tools menu and click the Mark Thread Resolved menu item? That will let everyone know that you have your answer.

    Thank you.

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