Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing formated text

Status
Not open for further replies.

esteva

Mechanical
Jun 28, 2001
20
US

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?
 
Replies continue below

Recommended for you

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. DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
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.
 
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.
Code:
Open ("C:\Temp\Report.txt") For Output As #1
    Print#1, sNameVariable
    Print#1, sAddressVariable
    Print#1, The Rest of Your Variables
Close #1
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
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 ?
 
You just need to create the entire string.
Code:
    sPath = "C:\SomePath\"
    sFile = "SomeFile.txt"
    Call Shell("C:\WINNT\NOTEPAD " & sPath & sFile, 1)
Hope this helps... DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
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:

[form.]PrintForm

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.

 
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).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top