how to color a text inside a text file

Hello Experts,
how can i make  colored text ia file.txt by code?



aitsu01Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Shanmuga SundaramConnect With a Mentor Director of Software EngineeringCommented:
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
 
Patrick MatthewsCommented:
Hello aitsu01,

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

Regards,

Patrick
0
 
aitsu01Author Commented:
hello  matthewspatrick
thank you for your reply.
can you suggest any other format fyle to use colored fonts?
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Shanmuga SundaramDirector of Software EngineeringCommented:
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
 
danaseamanCommented:
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
 
Shanmuga SundaramDirector of Software EngineeringCommented:
aitsu01, Did you get what you expected on your requirement.
0
 
aitsu01Author Commented:
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
 
Shanmuga SundaramDirector of Software EngineeringCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.