×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

VB programming for printing formatted text

VB programming for printing formatted text

RE: VB programming for printing formatted text

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.

RE: VB programming for printing formatted text

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

RE: VB programming for printing formatted text

(OP)
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 http://www.narendranath.itgo.com/mysoftware.html
and download the "Stokes"  program written in VB and advise any comments
or suggestions.

Narendranath R
narenr@narendranath.itgo.com
http://www.narendranath.itgo.com
Pipeline engineering is made easy with state of the art computer software, visit www.narendranath.itgo.com.

RE: VB programming for printing formatted text

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

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!


Resources