Ora devo dire che il processo di stampa parte, ma poi viene interrotto... come mai? Vi riposto il codice... l'ho un po' modificato...
classe Stampa
codice:
Option Explicit
Private font As String
Private size As Integer
Private bold As Boolean
Private italic As Boolean
Private underline As Boolean
Private strikethru As Boolean
Private Sub Class_Initialize()
font = "Arial"
size = 10
bold = False
italic = False
underline = False
strikethru = False
End Sub
Public Function setFont(a)
font = a
End Function
Public Function getFont()
getFont = font
End Function
Public Function setSize(a)
size = a
End Function
Public Function getSize()
getSize = size
End Function
Public Function setBold(a)
bold = a
End Function
Public Function getBold()
getBold = bold
End Function
Public Function setItalic(a)
italic = a
End Function
Public Function getItalic()
getItalic = italic
End Function
Public Function setUnderline(a)
underline = a
End Function
Public Function getUnderline()
getUnderline = underline
End Function
Public Function setStrikethru(a)
strikethru = a
End Function
Public Function getStrikethru()
getStrikethru = strikethru
End Function
Public Sub stampaTesto(testo)
Dim ritorno
If font = Empty Then
font = "Arial"
size = 10
bold = False
italic = False
underline = False
strikethru = False
End If
Printer.FontName = font
Printer.FontSize = size
Printer.FontBold = bold
Printer.FontItalic = italic
Printer.FontStrikethru = strikethru
Printer.Print testo
Printer.EndDoc
End Sub
Public Sub stampaEtichetta(a, b, c, d, e, f, g, h, i)
Etichetta.Label10.Caption = a
Etichetta.Label11.Caption = b
Etichetta.Label12.Caption = c
Etichetta.Label13.Caption = d
Etichetta.Label14.Caption = e
Etichetta.Label15.Caption = f
Etichetta.Label16.Caption = g
Etichetta.Label17.Caption = h
Etichetta.Label18.Caption = i
Etichetta.PrintForm
End Sub
Public Function getPrinter()
Dim str As String
Dim X As Printer
For Each X In Printers
str = str + X.DeviceName + "§"
Next
str = Left(str, Len(str) - 1)
getPrinter = str
End Function
Public Function setPrinter(a)
Dim X As Printer
Dim flag As Boolean
flag = False
For Each X In Printers
If X.DeviceName = a Then
' Imposta la stampante come predefinita di sistema.
Set Printer = X
flag = True
Exit For
End If
Next
setPrinter = flag
End Function
Form test:
codice:
Dim akka As Stampa
Private Sub bott_2_Click()
Set akka = New Stampa
MsgBox (akka.getPrinter())
End Sub
Private Sub bottone_Click()
Dim str As Boolean
Set akka = New Stampa
str = akka.setPrinter(test.tendina.Text)
If str = True Then
Call akka.stampaEtichetta("a", "b", "c", "d", "e", "f", "g", "h", "i")
End If
End Sub
Private Sub Form_Load()
With test
Dim X As Printer
For Each X In Printers
.tendina.AddItem X.DeviceName
Next
.tendina.ListIndex = 0
End With
End Sub