Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Printing formated text

Printing formated text

Printing formated text


I want to make a program that captures text fields from the user and print the information formated in a heading letter. I want the name, address, sale concept, amount, tax, etc. in especific areas of the sheet.
Could you help me?

RE: Printing formated text

Sounds like you want to create a small report. What application do you want to use for this? If you want a plain text file, just use the Print command to write the data to a .txt file and use the Shell command to open the document. If you want to use Word or Excel, you will need to fire up the respective application and create the report. Let me know what method you had in mind and I can help you out.

While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: Printing formated text

I want to make the program in VisualBasic. And when I execute the program, the user should fill the fields for information required and then print it in specific areas of the sheet.

RE: Printing formated text

What sheet? I understand that you want to use VB forms to get user input, but what do you want to do with the data? Typically, this would be written to a report of some kind. Do you want to send the data directly to the printer? It would be easier to format the information in a report file and open it up for the user to print manually.

Open ("C:\Temp\Report.txt") For Output As #1
    Print#1, sNameVariable
    Print#1, sAddressVariable
    Print#1, The Rest of Your Variables
Close #1

While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: Printing formated text

DSI, your note above regarding using the Print command to print data to a .txt file and using the Shell command to view the file worked well. I used Notepad to open and view the text file. However, the only way it worked was if the the name of the file to be opened was included in the Shell command at design time. I have a case where the file name is determined at run time and so I had to use a string variable to store the name of the file. However, it seems that the Shell command does not recognize the variable file name. For example, if the filename was a string variable called "resultsfile", Notepad would look for a file by the name of resultsfile.txt and tell me that it could not be found. Is there a way that this would work ?

RE: Printing formated text

You just need to create the entire string.

    sPath = "C:\SomePath\"
    sFile = "SomeFile.txt"
    Call Shell("C:\WINNT\NOTEPAD " & sPath & sFile, 1)

Hope this helps...

While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: Printing formated text

Thanks a lot. It did work.

RE: Printing formated text

The official "VB" way of doing this would be to just create a hidden form with all the formatting that you want, fill in the various data values when the user wants to print, and send it to the printer with the PrintForm method.

From MSDN:

Using the PrintForm Method

The PrintForm method sends an image of the specified form to the printer. To print information from your application with PrintForm, you must first display that information on a form and then print that form with the PrintForm method. The syntax is as follows:


If you omit the form name, Visual Basic prints the current form. PrintForm prints the entire form, even if part of the form is not visible on the screen. If a form contains graphics, however, the graphics print only if the form’s AutoRedraw property is set to True. When printing is complete, PrintForm calls the EndDoc method to clear the printer.

RE: Printing formated text

The "official VB" way to print a report would be to send formatted text to the printer object (Printer.Print "Send your text here"). The problem here is that you have to format your text yourself (the printer object does not handle word wrap, margins, etc).
If this is a small in-house project, I think the notpad/shell method is the easy route to go, but if you need more power you may want to look into a third party text formatting/print preview control (or roll your own).

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close