Solved

Color Problem with Rich Text Box vb6

Posted on 2009-06-29
4
478 Views
Last Modified: 2013-12-26
Hello, I am working on a messenger which has some chat rooms now the problem is when someone enters/leave a room it show in blue that user has entered/left but after a while when someone else enter/leave all the old textformatting comes to defualt (black) here is my code:


Public Sub AddStatusMessage(RTB As Object, _
    ByVal Color As Long, Message As String)
    If Not TypeOf RTB Is RichTextBox Then Exit Sub
   
    With RTB
        .SelStart = Len(.Text)
        .SelFontName = "Tahoma"
        .SelFontSize = 9
        .SelBold = False
        .SelItalic = False
        .SelUnderline = False
        .SelColor = Color
        .SelText = Message & vbCrLf
    End With
End Sub

IT works quite fine but how to remain other colors
0
Comment
Question by:BILAL69
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24738611
The code you have posted looks fine.

The symptom of losing all previous formatting and everything going to black is usually caused by setting the Text() property:

    RTB.Text = RTB.Text & "new message" & vbCrLf ' <---- this is wrong way to go about it

Do you have any other code that deals with the RichTextBox?...and if so, does it directly assign the Text() Property like above?
0
 
LVL 2

Author Comment

by:BILAL69
ID: 24738681
well i only use this code when someone enter/leave so.. when its not i just say txtChat.text = txtChat.text & themsg & vbcrlf

also how do i know the color in RGB() ? like if i want the pink color :-/
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 24738759
Therein lies the problem:

    txtChat.text = txtChat.text & themsg & vbcrlf

That will ERASE the previous formatting in the RTB.  You need to use code just like in your AddStatusMessage() method if you want to add something to the end without destroying all of your formatting.  =)

To pick your own color, use the RGB() function:
http://msdn.microsoft.com/en-us/library/zc1dyw8b(VS.80).aspx

So it would be something like:

    Dim myColor As Long
    myColor = RGB(255, 192, 203)
0
 
LVL 2

Author Comment

by:BILAL69
ID: 24738908
oh correct thnx :D
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now