printing in VB

Posted on 2004-11-02
Last Modified: 2010-05-18
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 ?????
Question by:lungwa
    LVL 53

    Accepted Solution

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

    2) Add a common dialog control named: cdl

    Dim iFileNum As Integer, s As String
      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
        Close iFileNum
      End If
    LVL 53

    Expert Comment

    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
    LVL 2

    Expert Comment

    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.SelBold = True
    end if

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now