printing in VB

I am the newbie in VB how can I print a text file in printer and some text i want to bold it before print out ?????
lungwaAsked:
Who is Participating?
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.

DhaestCommented:
Several possibilities to print a textfile:
1)
Open "c:\myfile.txt" For Input As #1
Do while Not Eof(1)
   Line Input #1, x$
   Printer.Print x$
Loop
Close 1
Printer.EndDoc

2) Add a common dialog control named: cdl

Dim iFileNum As Integer, s As String
 
  cdl.ShowOpen
  If Len(cdl.filename) > 0 Then
    iFileNum = FreeFile
    Open cdl.filename For Input As iFileNum
   
    Do While Not EOF(iFileNum)
      Line Input #iFileNum, s
      Printer.Print s
    Loop
   
    Printer.EndDoc
    Close iFileNum
  End If
0

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
DhaestCommented:
If you want to format text, you'll have to use the richtextbox

To make selected text bold, underlined, italic or strikethrough you can use the following code:

Statement Action
RichTextBox1.SelBold = True Makes the selected text Bold
RichTextBox1.SelItalic = True Makes the selected text Italic
RichTextBox1.SelUnderline = True Makes the selected text Underlined
RichTextBox1.SelStrikeThru = True Makes the selected text Strikethrough

To change the alignment, simply use this syntax:

RichTextBox1.SelAlignment = Alignment

Where alignment is one of the following constants:

Constant Alignment
vbRight Right
vbLeft Left
vbCenter Centre

So, the following code will set make the selected text underlined, and aligned to the right.

RichTextBox1.SelAlignment = vbRight
RichTextBox1.SelUnderline = True



To print out a formatted richtextbox:

'Name of Rich Text Box Control = rtf
'Write this code under Print Button

rtf.SelPrint Printer.hDC
rtf.SelStart = lastposition
rtf.SelLength = lastSelection
0
kouroshparsaCommented:
They are right. As the first example load the text into a richTextBox. You can keep the richtextbox hidden if you like so. Then lets say you want to make all numbers Bold. Use a loop to go through each character... then use this:
if isNumeric(charac ) then    'or if charac="important letter"
rtb.selstart=ind
rtb.SelBold = True
end if
0
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
Programming

From novice to tech pro — start learning today.

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.