Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

VB programming for printing formatted text 1

Status
Not open for further replies.

narenr

Marine/Ocean
Aug 4, 2000
97
Can anyone please provide a sample code or hint how to program formatted text printing with fonts specified in VB.
thanx in advance
Narendranath

Narendranath R
narenr@narendranath.itgo.com
Pipeline engineering is made easy with state of the art computer software, visit
 
Replies continue below

Recommended for you

I program often in VB 6.0 but I have never seen a direct VB utility for printing formatted text. You need the VB reports module; I'm sure it is available in the Enterprise Visual Studio but I don't have the reports module. The reports module is VB's method for sending stuff to the printer.
 
Here is a sample that I have pulled directly from a program that I wrote a while back. I have not altered the sub in any way. It should give you an idea on how to print.

Note: cdOne is the common dialog control...


Private Sub cmdPrint_Click()
Dim i As Integer
Dim count As Integer
Dim searchedFrom As String
Dim searchedTo As String
Dim defaultPrinter As String

'diable the print button
cmdPrint.Enabled = False



searchedFrom = CStr(dtpFrom.Month) + "/" + CStr(dtpFrom.Day) + "/" + CStr(dtpFrom.Year)
searchedTo = CStr(dtpTo.Month) + "/" + CStr(dtpTo.Day) + "/" + CStr(dtpTo.Year)
count = lsvResults.ListItems.count

'have the printer dialog come up and allow the user to pick a default printer


Const ErrCancel = 32755
cdOne.CancelError = True
On Error GoTo errorPrinter
cdOne.Flags = 64
'see the Help on Flags Properties (Print
' Dialog)


cdOne.PrinterDefault = True
cdOne.ShowPrinter
MsgBox "Printing....", vbInformation, "Print"
mouseWait 'show the hourglass to indicate that it may take a while
Printer.FontName = "Arial"
Printer.FontBold = True
Printer.FontSize = 7
'================================
Printer.Print "Printed on: " + Format$(Now, "dddd, mmm dd, yyyy hh:mm AM/PM")
Printer.Print "Search String: " + cmbSearch.Text

If chkDate.Value = vbChecked Then 'then print the date range, otherwise do not
Printer.Print "Date Range: " + searchedFrom + " To " + searchedTo
Else
Printer.Print "Date Range: All Available Alarm Files "
End If

'================================
Printer.FontBold = False
Printer.FontSize = 7.5
'================================
Printer.Print " "
Printer.Print "MM DD YY"
Printer.FontSize = 10

For i = 1 To count
Printer.Print lsvResults.ListItems(i).Text 'this may start at zero and may need to be changed

If i Mod 60 = 0 Then 'start a new page
Printer.Print " "
Printer.Print " "
Printer.Print " Page " + Format(Printer.Page, "#,###")
Printer.NewPage
Printer.FontSize = 7
'================================
Printer.Print "Printed on: " + Format$(Now, "dddd, mmm dd, yyyy hh:mm AM/PM") '+ " Page " + Format(Printer.Page, "#,###")
Printer.Print "Search String: " + cmbSearch.Text

If chkDate.Value = vbChecked Then 'then print the date range, otherwise do not
Printer.Print "Date Range: " + searchedFrom + " To " + searchedTo
Else
Printer.Print "Date Range: All Available Alarm Files "
End If

'================================

Printer.FontBold = False
Printer.FontSize = 7.5
Printer.Print " "
Printer.Print "MM DD YY"
Printer.FontSize = 10
End If

Next i
'================================
Dim numLinesDown As Integer 'the number of lines to drop the page number down
Dim numLinesToAdd As Integer 'number of lines to add to the last page to get the page number in the right spot

numLinesDown = count - (60 * (Printer.Page - 1))
numLinesToAdd = 63 - numLinesDown


For i = 1 To numLinesToAdd - 1
Printer.Print " "
Next i

Printer.Print " Page " + Format(Printer.Page, "#,###")
Printer.EndDoc
mouseUnWait
cmdPrint.Enabled = True
'================================

Exit Sub 'exit to avoid error handler......
errorPrinter:
If Err.Number = ErrCancel Then
Exit Sub
End If
Resume

End Sub


Troy Williams
fenris@hotmail.com

I am a recent Mining Engineering Graduate with an interest in Genetic Algorithms, Engineering and Computers and Programming. I also have an interest in mineral economics
 
Troy

Thanx for the sample code, I had managed to print formatted text,
however I am not very comfortable to print scientific equation very
easily. Normally what I do is first write the output file from the
program and then readline and print. I am still improvising it.
Please visit my website and download the "Stokes" program written in VB and advise any comments
or suggestions.

Narendranath R
narenr@narendranath.itgo.com
Pipeline engineering is made easy with state of the art computer software, visit
 
I will check out your software, but as far as scientific equations go. I don't think that it is easy. What I have seen mathematica do is output the equations as images (jpg,bmp,etc.).This might be of some use. Unfortunately I little experience with generating graphics.

You might also try using exotic fonts, they may at least allow you to reproduce some of the mathematical notations..

Good Luck

Troy Williams
fenris@hotmail.com

I am a recent Mining Engineering Graduate with an interest in Genetic Algorithms, Engineering and Computers and Programming. I also have an interest in mineral economics
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor