Home > Microsoft .Net Development Tips > ARCHIVE: Tips & Tricks > Text File Printing
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ARCHIVE: TIPS & TRICKS

Text File Printing


dave sharpe
12.05.2000
Rating: -3.38- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Text File Printing
David Sharpe

New to VB programming? David Sharpe, one of our subscribers, was as well, when he ran into a problem. It's an easy problem, but sometimes the easiest problems cause the most trouble. Anyway, David sends this tip in hopes that his investigations will help others. If you have a better solution to this problem, why not share it with other VB developers. If we pick your tip, you'll get a free SearchVB denim shirt.

I am somewhat new to VB, but I have a good background in DOS Foxpro and some exposure to QuickBasic. A VB 6 program I'm writing was to create a document as a text file on the PC (to store for historical reasons) and then simply send it to the printer for a hard copy. I initially found it difficult to determine how to create the local text file, then really got lost when I attempted to find out how to get it printed.

I was a finally able to figure it out, and thought my findings might be helpful or informative in some way to others.

The basic creation of the local text file seems to follow older basic structures, although I could find no document in MSDN that helped. So here's how I did it.

The following would read all of the lines (txtLine) in the file "TxtFileToRead" and write each line into "TxtFileToWrite"

Dim txtLine as String
Dim TxtFileToRead  as string
Dim TxtFileToWrite as string

Open TxtFileToRead  for Input  as #1
Open TxtFileToWrite for Output as #2

Do While Not EOF(1)

Line Input #1 , txtLine
Print #2 , txtLine

Loop

Close #1
Close #2

To print a file requires use of two methods of the "Printer Object". The follwing will read each line (txtTheLine) in a text file (txtTheFile), store it in the Printer Object and then causes the Printer Object to be actually be sent to the printer.

dim txtTheLine as string        'declare the variable
    'that you intend to
    'store the lines that
    'are read in.

dim txtTheFile as string 'declare the variable
    'that you intend to use to
    'store the file's name.

txtTheFile = "c:program filesvb projectsmy_data.txt"

    'assign the file's fully
    'qualified path and name
    'to the variable.

Open txtTheFile for Input as #1 'Open the file.

Do While Not Eof(1)  'Prepare to read the file
    '(while not Eof(1) causes
    'termination when the End
    'Of File is reached.

Line Input #1, txtTheLine 'Read a line
Printer.Print txtTheLine 'Store the line into the
    'Printer Object

Loop    'Repeat the process of
    'reading lines

Printer.Enddoc   'Causes the lines stored
    'via the "Printer.Print"
    'line above to be sent to
    'the printer. It also sends
    'a Form Feed to cause
    'the printed page to be
    'printed properly.

I hope that this will be of benefit to others.

Thanks, David. For your interest in SearchVB, we'll be sending you a denim shirt.

"I've been wrestling with PCs and databases since 640k of ram was 'Dreamed for,' neither Dbase nor MSDos had revision levels, and GW-Basic was IT!"
Dave Sharpe works in the Materials Management Department of BellSouth Communication Systems in Roanoke,VA. His major functions involve ad hoc reporting from the corporate Oracle databases using MSAccess.


Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
ARCHIVE: Tips & Tricks
SearchVB wants your tips
Find out what VS.NET modules are installed
Retrieving icons from an EXE-file
Toggling Boolean values
VS.NET multiple tabbed windows
Set the value of a DataField in code behind
Easy grid design
Open using last Visual Studio.NET layout
Save development time by using inherited forms
Reusing code in VS.NET

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts