VBScript to Change the font


  I have a text file that has some formatted content.
I want to change the font of this text file using vbscript.
Can someone kindly help with the sample code?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
A plain text file has no font information. Please explain your context.
pvsbandiAuthor Commented:
It is a text file. When trying to print, the text is wrapping because of the font size. So, the idea is to decrease the font and be able to display the information without wrapping.
ste5anSenior DeveloperCommented:
How do you print it?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

pvsbandiAuthor Commented:
it's the users who print it manually. Letter -> Portrait
I can ask them to change the layout but not everyone knows to do it.
ste5anSenior DeveloperCommented:
Well, let them use Wordpad or Word.. As long as they print it manually, you cannot do much.
pvsbandiAuthor Commented:
i need to somehow change the text content so it doesn't wrap in certain places
ste5anSenior DeveloperCommented:
Then you need to reformat it. Insert line breaks after 72 characters.
pvsbandiAuthor Commented:
any example code you can help me with?
ste5anSenior DeveloperCommented:
E.g. something like

Option Explicit

Const fsoForReading = 1
Const fsoForWriting = 2

Function LoadStringFromFile(filename)
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(filename, fsoForReading)
    LoadStringFromFile = f.ReadAll
End Function

Sub SaveStringToFile(filename, text)
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(filename, fsoForWriting)
    f.Write text
End Sub

Sub ReformatString(text)

    Dim count, result
    text = Replace(text, vbCrLf & vbCrLf, "@#|<>")
	For count = 1 to Len(text)
	    result = result & Mid(text, count, 1)
		If count mod 76 = 0 Then
		   result = result & vbCrLf
		End If
	Next count
	ReformatString = Replace(result, "@#|<>", vbCrLf & vbCrLf)
End Sub

SaveStringToFile "f.txt", ReformatString(LoadStringFromFile("f.txt"))

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pvsbandiAuthor Commented:
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.