?
Solved

send string to richtextbox

Posted on 2003-03-27
3
Medium Priority
?
174 Views
Last Modified: 2012-05-04
Hello,

I need to send a string to a richtextbox in two colors, how can i do this???


Datastring = "this is blue, this is red"


I hope someone can help me

Thanks
0
Comment
Question by:Tk
3 Comments
 
LVL 9

Accepted Solution

by:
GivenRandy earned 80 total points
ID: 8217341
Core code is:

---
RichTextBox1.SelStart = 3  ' Some Start Value
RichTextBox1.SelLength = 5  ' Some Length Value
RichTextBox1.SelColor = vbRed  ' Some Color
---

For a function that adds text of a specified color, use AddColorText:

---
Public Sub AddColorText(RTB As RichTextBox, Color As Long, Text As String)
    Dim R As Long
    Dim G As Long
    Dim B As Long
   
    RTB.SelStart = Len(RTB.Text)
    R = Color Mod &H100
    G = (Color \ &H100) Mod &H100
    B = (Color \ &H10000) Mod &H10000
    RTB.SelRTF = "{{\colortbl;\red" & CStr(R) & "\green" & CStr(G) & "\blue" & CStr(B) & ";}" & "{\cf1 " & Text & "}}"
End Sub
---

This control does a lot of the work for more complex approaches:

http://www.vbaccelerator.com/codelib/richedit/richedit.htm
0
 

Expert Comment

by:CleanupPing
ID: 8531528
Hi Tk,
This old question (QID 20564967) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9440938
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept GivenRandy's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

615 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