I'm making a simple 2 person chat prog. I want to have different colors for the user names for "UserA" and "UserB" and for them to be in bold. The colors dont work they way I would like them to. The colors only appear on UserA, (the one who was listening for the connection request), and it doesnt have separate coloring for either user. Just one color or the other. Here is the complete source for my program:
Thanks in advance.Code:Option Explicit Public incomingbuffer As Variant Dim AreWeOn As Boolean Dim IsError As Boolean Private Sub b_con_Click() l_stat.Caption = "Attempting to connect to " & t_Ipcon.Text & " on port 2100..." If Winsock1.State <> sckClosed Then Winsock1.Close Winsock1.RemoteHost = t_Ipcon.Text Winsock1.Connect AreWeOn = False IsError = False Do Until AreWeOn = True Or IsError = True DoEvents: DoEvents: DoEvents: DoEvents If Winsock1.State = sckConnected Then AreWeOn = True If Winsock1.State = sckError Then MsgBox "There has been a communication error.", , "..Error.." IsError = True Exit Sub End If Loop l_stat.Caption = "Connected to " & t_Ipcon.Text & " on port 2100..." con_IP.Caption = t_Ipcon.Text con_port.Caption = "2100" End Sub Private Sub b_discon_Click() If Winsock1.State <> sckClosed Then Winsock1.Close Winsock1.Listen l_stat.Caption = "Listening for connection on port 2100..." End Sub Private Sub b_sendout_Click() Winsock1.SendData t_input.Text AddUserText "You", t_input.Text t_input.Text = "" End Sub Private Sub Form_Load() Winsock1.Listen l_stat.Caption = "Listening for connection on port 2100..." End Sub Private Sub Form_Unload(Cancel As Integer) If Winsock1.State <> sckClosed Then Winsock1.Close End Sub Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) If Winsock1.State <> sckClosed Then Winsock1.Close Winsock1.Accept requestID l_stat.Caption = "Connected to " & Winsock1.RemoteHost & " on port 2100..." con_IP.Caption = Winsock1.RemoteHost con_port.Caption = Winsock1.RemotePort End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Winsock1.GetData incomingbuffer, vbString AddRecipText "Recipiant", incomingbuffer End Sub Sub AddRecipText(Username As String, Text As Variant) t_output.SelStart = Len(t_output.Text) t_output.SelLength = 0 t_output.SelBold = True t_output.SelColor = RGB(0, 0, 255) t_output.Text = t_output.Text & Username & " said: " t_output.SelStart = Len(t_output.Text) t_output.SelLength = 0 t_output.SelBold = False t_output.SelColor = RGB(0, 0, 0) t_output.Text = t_output.Text & Text & vbCrLf 't_output.SelBold = False 't_output.SelColor = RGB(0, 0, 0) End Sub Sub AddUserText(Username As String, Text As Variant) t_output.SelStart = Len(t_output.Text) t_output.SelLength = 0 t_output.SelBold = True t_output.SelColor = RGB(255, 0, 0) t_output.Text = t_output.Text & Username & " said: " t_output.SelStart = Len(t_output.Text) t_output.SelLength = 0 t_output.SelBold = False t_output.SelColor = RGB(0, 0, 0) t_output.Text = t_output.Text & Text & vbCrLf 't_output.SelBold = False 't_output.SelColor = RGB(0, 0, 0) End Sub Private Sub Winsock1_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) MsgBox "There has been a communication error.", , "..Error.." End Sub --Descriptions of controls-- t_output - RichText - Where the "chat log" is displayed. t_input - TextBox - Where you would type the message that is sent. t_Ipcon - TextBox - User enters IP or Hostname of who to connect to here con_Ip - Label - displaying the IP you are connect to. (only works partially) con_port - Label - displaying the port you are connected to always 2100. l_stat - Label - displaying the current connection status. (only works partially) b_discon - CommandButton - Disconnect button b_sendout - CommandButton - Send button b_con - CommandButton - Connect button





Reply With Quote