473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.activedocument.print - it jumps to the error handler. I have also tried application.activedocument.printform - 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.
Mar 26 '07 #1
1 2706
Function PrintWrapped(ByVal 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.ScaleWidth ' Only check this once
lInputWidth = Printer.TextWidth(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.TextWidth(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.TextWidth(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(strWork, " ", 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.TextWidth(strInput)
' Page break if requested


If bPageBreak Then


If Printer.CurrentY > (Printer.ScaleHeight - Printer.TextHeight(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(True, False)
End Sub
Apr 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dan Kean | last post by:
Hi all, how can I bring a file browser up to select a file then send the path to a textbox and display it (will be image file) also can I limit extensions to *.bmp etc? thanx for any help!...
1
by: quest | last post by:
How do I create full screen dialog in C# ? Full screen in the sense that it covers everything on the screen including the tast bar. Thanks.
4
by: MC D | last post by:
What's the best way to have a modal dialog that will only allow the selection of a FOLDER, rather than a file? Is there a property of the openFileDialog I'm missing, or is there another control...
0
by: hamil | last post by:
I have a graphic file demo program that almost works. My form has a PageSetupDialog, PrintPreview, PrintDialog, and a PrintDocument control. Sample code follows. Now here is the quesion. When I...
2
by: Wayne | last post by:
I'm using the following line of code to print only the first page of a report: DoCmd.PrintOut acPages, 1, 1 This works fine with one limitation. It sends the report to the default printer. ...
3
by: Lloydm | last post by:
I built a timesheet and finally got all my functions working. Iv'e searched through the vb forum but had no luck finding a "print job" script. After saving file and before exit, I would like a...
4
by: Ian | last post by:
I have an Access 97 database, on a Report I have the print option set to print to the PC’s default printer rather than a printer selected from the list. My question is: Can I allow the user to...
2
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
0
by: =?Utf-8?B?VG9t?= | last post by:
I have a number of printers on my home office network, running XP Pro. Two are networked and the other two are parallel port. Everything works, but lately it seems like when I select a printer from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.