Autoprint screen (no dialog box to select printer)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmos1981
    New Member
    • Mar 2007
    • 1

    Autoprint screen (no dialog box to select printer)

    Visual Basic 6.3 - i am auto printing a screen using vb. i dont want the print dialog box to appear. the page should just print to the default printer. alternatively if i could use "sendkeys" to dialog box this would be okay but vb code waits for a reply to the print dialog box.. The line I am getting an error on is: application.act ivedocument.pri nt - it jumps to the error handler. I have also tried application.act ivedocument.pri ntform - Note: The application is being made using a process control system which uses VB 6.3 for the GUI, it may be a scaled down version of VB 6.3 - I am not familiar with the printer object, I have tried printer.print but I received an error message saying :variable not defined, I understand what this means, but is the printer object something I can place on the form (like Winsock control) or is it just like a variable that I need to define. I have looked up a few pages on printer object but they havent given me the info i need. Thanks for the help.
  • R Muruganandhan
    New Member
    • Apr 2007
    • 1

    #2
    Function PrintWrapped(By Val strInput As String, Optional bPageBreak As Boolean = False, Optional bBreakWords As Boolean = False) As Integer
    ' strInput - The string to be printed
    ' bPageBreak - Set this to true for the
    ' code to check for end of page,
    'and wrap to a new page.
    ' bBreakWords - Set this to True if you


    ' do not want to break the line
    'at a space if possible (i.e. if you don
    't care if it
    'breaks words into two pieces)
    '
    ' RETURNS: Number of lines printed. Allo
    ' ws you to track to end of page
    Dim lPointer As Long
    Dim lPosition As Long
    Dim lPtrWidth As Long
    Dim lInputWidth As Long
    Dim iLineCount As Integer
    Dim strWork As String
    lPtrWidth = Printer.ScaleWi dth ' Only check this once
    lInputWidth = Printer.TextWid th(strInput)



    Do While lInputWidth > lPtrWidth
    ' Estimate breakpoint
    lPosition = Int((lPtrWidth / lInputWidth) * Len(strInput))
    strWork = Left$(strInput, lPosition)
    ' Find max that can print on a line
    ' First, if you have text that is shorte
    ' r than the max possible, then
    ' add additional characters to the work
    ' string


    Do While Printer.TextWid th(strWork) < lPtrWidth
    If Len(strWork) = Len(strInput) Then Exit Do
    strWork = Left$(strInput, Len(strWork) + 2)
    Loop
    ' Now trim characters off the work strin
    ' g until it is shorter than
    ' the printer width


    Do While Printer.TextWid th(strWork) > lPtrWidth
    strWork = Left$(strWork, Len(strWork) - 1)
    Loop
    ' If you are breaking at spaces, then...
    '


    If Not bBreakWords Then

    lPointer = Len(strWork)
    ' ************ VB3 - VB5 Code **********
    ' *****
    ' If using VB6, then uncomment the line
    ' of code
    ' containing th InStrRev function, and c
    ' omment
    ' out this code.
    ' *************** *************** ********
    ' *****
    lPosition = lPointer

    ' Hunt for a space in the string


    Do Until lPosition = 1
    If Mid(strWork, lPosition, 1) = " " Then Exit Do
    lPosition = lPosition - 1
    Loop
    ' ************* VB6 Code **************
    ' This line replaces the above block for
    ' VB6 ONLY
    ' *************** *************** *******
    'lPosition = InStrRev(strWor k, " ", lPoi
    ' nter)
    ' ************* End Optional Code
    ' If there is no space before the first
    ' character, then we will
    ' be breaking within a word



    If lPosition > 1 Then ' Found a space
    strWork = Left(strWork, lPosition - 1)


    If lPosition < Len(strInput) Then
    strInput = Mid(strInput, lPosition + 1)
    Else
    strInput = ""
    End If
    Else ' Must break In word
    strInput = Mid(strInput, lPointer + 1)
    End If
    Else


    If Len(strInput) > lPointer Then
    strInput = Mid(strInput, lPointer + 1)
    Else
    strInput = ""
    End If
    End If
    Printer.Print strWork
    iLineCount = iLineCount + 1
    lInputWidth = Printer.TextWid th(strInput)
    ' Page break if requested


    If bPageBreak Then


    If Printer.Current Y > (Printer.ScaleH eight - Printer.TextHei ght(strWork)) Then
    Printer.NewPage
    End If
    End If
    Loop



    If Len(strInput) > 0 Then
    Printer.Print strInput
    iLineCount = iLineCount + 1
    End If
    PrintWrapped = iLineCount
    End Function

    Private Sub Command1_Click( )
    Call PrintWrapped(Tr ue, False)
    End Sub

    Comment

    Working...