Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [vb6] classe per stampa

    ciao a tutti, sto cercando di creare una DLL per fare delle stampe in ASP... premetto che sono nubbio del VB, quindi portate pazienza!

    Il mio progetto l'ho diviso in una classe (che se ho capito bene poi sarà la mia DLL) e dei form (videate da stampare).
    Per il momento il progetto è un EXE perchè volevo testarlo direttamente da VB.
    Ora veniamo al codice (lungo, ma moooooolto semplice)
    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
    Il primo form si chiama etichetta ed ha solo delle label.
    Il secondo si chiama test ed ha un menu a tendina (visualizza le stampanti) ed un bottone per avviare la stampa. Ecco il codice
    codice:
    Dim akka As Stampa
    
    Private Sub bottone_Click()
     Dim X As Printer
     For Each X In Printers
      If X.DeviceName = test.tendina.Text Then
       ' Imposta la stampante come predefinita di sistema.
       Set Printer = X
       Exit For
      End If
     Next
     akka.stampaTesto ("ciao")
    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
    Il problema da nubbio è che mi da errore quando richiamo una qualsiasi funzione della classe stampa:
    codice:
    errore di run-time '91'
    variabile oggetto o variabile del blocco With non impostata
    L'errore me lo da su akka.stampaTesto ("ciao")
    Potete aiutarmi?

  2. #2
    hai creato l'oggetto akka prima di utilizzarlo?
    xxx

  3. #3
    in effetti non l'avevo instanziato... ora ho aggiunto...
    Grazie

  4. #4
    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

  5. #5
    up

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.