Printing labels on a dot matrix printer - what does this code do

L

Laurence Lombard

In my search for a method to print labels on a dot matrix printer from Excel
I found the post http://www.theofficeexperts.com/for...hread.php?t=831 which
gave a fine solution, but there is a bit of code which I do not understand.
(My VBA is self taught via trial and error).

PauseTime = 2 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop

..
The code writes to PRINTLABEL.TXT and then executes a PRINTLABEL.BAT (which
contains the line "copy PRINTLABEL.TXT lpt1") for the number of times one
wants the label printed. I suspect the code above slows down the execution
so that the BAT file does not run faster than the printer can print.

Thanks
Laurence

An abbreviated version of the code follows for details sake. It works well
and I thought other that use this forum might also find it useful.

----------------------------------------------------------------------------
--------------
Private Sub PRINTLABEL_Click()
On Error GoTo Err_PRINTLABEL_Click

Dim Message, Title
Dim NUMCOPIES As Integer
Dim PauseTime, Start, Finish, TotalTime
Dim PRINTLINE1 As Variant
Dim PRINTLINE2 As Variant
Dim PRINTLINE3 As Variant
Dim PRINTLINE4 As Variant
Dim PRINTLINE5 As Variant
Dim PRINTLINE6 As Variant
Dim RetVal

Open "c:\PRINTLABEL.TXT" For Output Shared As #1


PRINTLINE1 = [Mr/Mrs] & " " & [ContactFirstName] & " " & [ContactLastName]
PRINTLINE2 = [CompanyName]
PRINTLINE3 = [Address1]
PRINTLINE4 = [Address2]
PRINTLINE5 = [POB]
PRINTLINE6 = [City] & ", " & [StateOrProvince] & " " & [PostalCode]


Print #1, " "
Print #1, (PRINTLINE1)
Print #1, (PRINTLINE2)
Print #1, (PRINTLINE3)
Print #1, (PRINTLINE6)
Print #1, " "
Close #1

NUMCOPY:

PauseTime = 2 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop

Message = "Enter the number of copies"
NUMCOPIES = InputBox(Message, Title, NUMCOPIES + 1)
For counter = 1 To NUMCOPIES

PauseTime = 2 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop


RetVal = Shell("C:\LABPRT.BAT") ' PRINTS LABEL.
Next counter

Exit_PRINTLABEL_Click:
Exit Sub

Err_PRINTLABEL_Click:
MsgBox Err.Description
Resume Exit_PRINTLABEL_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top