Solved

how to color a text inside a text file

Posted on 2007-11-26
8
152 Views
Last Modified: 2010-04-30
Hello Experts,
how can i make  colored text ia file.txt by code?



0
Comment
Question by:aitsu01
8 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 20350050
Hello aitsu01,

Text files by definition do not have formatting such as colored fonts.

Regards,

Patrick
0
 

Author Comment

by:aitsu01
ID: 20350144
hello  matthewspatrick
thank you for your reply.
can you suggest any other format fyle to use colored fonts?
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20350147
you cannot bring colour in text files. but you can load that text file in vb richtextbox and you can give colours to it. for further idea regarding this

Please look at

http://www.ostrosoft.com/vb/projects/rtf_color/index.asp
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 22

Expert Comment

by:danaseaman
ID: 20350187
You can load the plain text into a RichTextBox control and then apply color or font formatting by code.
At this point though you will have to save the file as TextRTF to preserve the formatting.
Option Explicit
 
Private Sub Form_Load()
   Dim s As String
   s = "Hello World"
   RichTextBox1.Text = s
   RichTextBox1.SelLength = Len(s)
   RichTextBox1.SelColor = vbRed
   RichTextBox1.SelBold = True
   RichTextBox1.SelLength = 0
   'Save RichTextBox1.TextRTF to file
   Debug.Print RichTextBox1.TextRTF
End Sub

Open in new window

0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20356607
aitsu01, Did you get what you expected on your requirement.
0
 

Author Comment

by:aitsu01
ID: 20356643
hello shnsunder,
i am working on it but my problem is how to save the text color on my file.txt
how do can i add a richtextbox in my project??
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20357027
Press Ctrl T and choose Microsoft Rich textbox control 6.0.

you can find the rtf control in the tools menu.

insert it in your form.
0
 
LVL 17

Accepted Solution

by:
Shanmuga Sundaram earned 125 total points
ID: 20357048
Sorry you can find the rtf control in the tools box.

once you are able to get the colur in the richtext box then save it in a file using RichTextBox1.SaveFile "C:\123.txt". So that you can open this file in future which will consists of colur formatting codes inside it.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

776 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