|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Chat Program Problem
I have followed the tutorial on making a chat program in vb6 but i'm having one small problem. When i send the text to the txtIn box, it only shows one line of text only, even when you keep sending more text to it, it deletes the first line and replaces it. I am new to programming, about 1 week so if someone could take the time to check my code and point me in the right direction I would be most appreciated
thanks Option Explicit Private Sub cmdClose_Click() 'Disable the outgoing buttons and tell the user 'that the connection has been closed wsChat.Close cmdClose.Enabled = False cmdSend.Enabled = False txtName.Enabled = True cmdListen.Enabled = True cmdConnect.Enabled = True txtIn.text = "----- Connection Closed -----" & vbCrLf End Sub Private Sub cmdConnect_Click() If txtIp.text = "" Or txtName.text = "" Then MsgBox "You must enter both an IP and alias first!", vbCritical, "Error!" txtName.SetFocus Exit Sub End If On Error Resume Next 'Connecting the IP that is placed in the txtIp.text wsChat.Close wsChat.Connect txtIp.text, 10000 cmdClose.Enabled = True cmdListen.Enabled = False cmdConnect.Enabled = False txtName.Enabled = False End Sub Private Sub cmdExit_Click() Unload Me End Sub Private Sub cmdListen_Click() If txtName.text = "" Then MsgBox "You must enter an alias first!", vbCritical, "Error!" txtName.SetFocus Exit Sub End If 'Place the local IP into this textbox and wait for a chat invitation. txtIp.text = wsChat.LocalIP wsChat.Close wsChat.LocalPort = 10000 wsChat.Listen cmdClose.Enabled = True cmdListen.Enabled = False cmdConnect.Enabled = False txtName.Enabled = False txtIn.text = "----- Waiting for Connection -----" End Sub Private Sub cmdSend_Click() On Error GoTo Error 'Send the data to the remote user wsChat.SendData "[" & txtName.text & "] " & txtOut.text txtIn.text = "[" & txtName.text & "] " & txtOut.text 'Clear out typed text and refocus on the box txtOut.text = "" txtOut.SetFocus Error: Exit Sub End Sub Private Sub txtIn_Change() txtIn.SelStart = Len(txtIn.text) End Sub Private Sub txtOut_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdSend_Click txtOut.SetFocus KeyAscii = 0 End If End Sub Private Sub wsChat_Connect() Do DoEvents Loop Until wsChat.State = sckConnected Or wsChat.State = sckError If wsChat.State = sckConnected Then 'Tell the user that the connection has been established txtIn.text = "----- Connection Established -----" & vbCrLf cmdSend.Enabled = True txtName.Enabled = False txtOut.SetFocus Else 'Tell the user that the connection has failed txtIn.text = "----- Connection Failed -----" & vbCrLf End If End Sub Private Sub wschat_ConnectionRequest(ByVal requestID As Long) 'It accepts just one argument (which is automatically provided by Winsock), which is a unique identifier representing the connection request from the client. 'Switch to the code window and select the ConnectRequest method of our Winsock object. Enter the following code: wsChat.Close wsChat.Accept requestID 'If the remote system requests a connection, accept it and connect txtIn.text = "----- Connection Established -----" & vbCrLf 'Tell the user that the connection has been established cmdSend.Enabled = True txtName.Enabled = False txtOut.SetFocus End Sub Private Sub wsChat_DataArrival(ByVal bytesTotal As Long) Dim incoming As String 'Tell the Winsock control to place the incoming data into a string. 'Then call the function to print the data into the "Incoming Data" textbox. wsChat.GetData incoming txtIn.text = incoming End Sub Private Sub wsChat_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) If Number <> 0 Then txtIn.text = "----- Error [" & Description & "] -----" & vbCrLf Call cmdClose_Click End If End Sub |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Chat Program Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|