|
-
Jun 30th, 2006, 11:33 AM
#1
Thread Starter
Member
[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.
-
Jun 30th, 2006, 11:50 AM
#2
Lively Member
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.
-
Jun 30th, 2006, 11:53 AM
#3
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:
Dim strIP As String
strIP = txtIPAddress.Text
Then us strIP for whatever you want.
-
Jun 30th, 2006, 12:00 PM
#4
Addicted Member
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?
-
Jun 30th, 2006, 12:12 PM
#5
Thread Starter
Member
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:
Private Sub Command1_Click()
Dim strIP As String
strIP = txtIPAddress.Text
If insertIP <> "" Then
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.RemoteHostIP = strIP
Winsock1.RemotePort = 5000
Winsock1.LocalPort = 0
Winsock1.Connect
End If
End Sub
Private Sub Commandsend_Click()
If Winsock1.State = sckConnected Then
Winsock1.SendData (txtname) & ": " & (txtchat)
DoEvents
txtmain.Text = txtmain.Text & vbCrLf & (txtname) & ": " & (txtchat)
txtmain.SelStart = Len(txtmain.Text)
End If
txtchat = ""
End Sub
Private Sub Winsock1_Connect()
MsgBox "Connected"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim chatdata As String
Winsock1.GetData chatdata
txtmain = (txtmain) & vbCrLf & chatdata
txtmain.SelStart = Len(txtmain.Text)
End Sub
-
Jun 30th, 2006, 12:27 PM
#6
Re: How do I input an IP address into a chat program?
Try this
VB Code:
Dim strIP As String
strIP = txtIPAddress.Text
If insertIP <> "" Then
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.RemoteHostIP = strIP
Msgbox strIP
Winsock1.RemotePort = 5000
Winsock1.LocalPort = 0
Winsock1.Connect
End If
Is the IP address that you want in the message box?
-
Jun 30th, 2006, 12:42 PM
#7
Thread Starter
Member
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:
Private Sub Command1_Click()
Dim strIP As String
strIP = txtIPAddress.Text
If strIP <> "" Then
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.RemoteHost = strIP
Winsock1.RemotePort = 5000
Winsock1.LocalPort = 0
Winsock1.Connect
End If
End Sub
Private Sub Commandsend_Click()
If Winsock1.State = sckConnected Then
Winsock1.SendData (txtname) & ": " & (txtchat)
DoEvents
txtmain.Text = txtmain.Text & vbCrLf & (txtname) & ": " & (txtchat)
txtmain.SelStart = Len(txtmain.Text)
End If
txtchat = ""
End Sub
Private Sub Winsock1_Connect()
MsgBox "Connected"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim luvlydata As String
Winsock1.GetData luvlydata
txtmain = (txtmain) & vbCrLf & luvlydata
txtmain.SelStart = Len(txtmain.Text)
End Sub
Last edited by BryanW; Jun 30th, 2006 at 12:53 PM.
-
Jun 30th, 2006, 12:43 PM
#8
Re: How do I input an IP address into a chat program?
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|