Buongiorno a tutti,
Premesso che sto usando un controllo data e una DBGrid, ho un probema nella stampa
Per quanto riguarda le righe orrizzontali tutto funziona...nelle righe verticali no.
Non le impacca come dovrebbe, mi fa solo alcune righe nel mezzo del testo...Perchè?
So che sto sbagliano qualche cosa ma non capisco dove.
Vi posto il codice, sperando aver capito come si fa
Se c'è qualcuno che riesce a capire dove sbaglio!
Grazie


codice:
Function pad1(stringa As String, lung As Integer) As String
  pad1 = Left$(stringa & Space(lung), lung)
End Function

Function valida(dato As Variant) As String
Select Case VarType(dato)
  Case vbNull: valida = vbNullString
  Case vbInteger: valida = CStr(dato)
  Case Else: valida = dato
  End Select
End Function

Private Sub Stampa()
Screen.MousePointer = vbHourglass
Dim aColWidth(10) As Integer, aPosVLine(10) As Integer
Dim sHeader As String, bar As String, riga As String
Dim ws As Workspace, db As Database, tb As Recordset
Dim i, msup, msin, mdes, colx As Integer
Dim maxr, rec, righe, pag As Integer

bar = Chr(32)

For i = 0 To 10
  aColWidth(i) = CInt(Array(15, 15, 18, 16, 8, 8, 15, 8, 11, 11, 18)(i))
     sHeader = sHeader + bar + pad1(DBGrid1.Columns(i).Caption, aColWidth(i))
       aPosVLine(i) = msin + aColWidth(i) + 1
       msin = aPosVLine(i)
  Next

 Set ws = DBEngine(0)
  Set db = ws.OpenDatabase(Data1.DatabaseName)
  Set tb = db.OpenRecordset(Data1.RecordSource)
  tb.MoveLast
  tb.MoveFirst

  Printer.Orientation = vbPRORPortrait
  Printer.FontName = "Courier"
  Printer.FontSize = 10
  Printer.ScaleMode = vbCharacters
  mdes = Int(Printer.ScaleWidth)
  maxr = Int(Printer.ScaleHeight) - 10
  
If maxr > tb.RecordCount Then maxr = tb.RecordCount

  msin = (mdes - Len(sHeader)) / 2
  colx = msin + 1
  
  For pag = 1 To tb.RecordCount Step maxr
  
  Printer.CurrentY = 1
  Printer.Print Tab(colx); DBGrid1.Caption; " (pagina"; Str(pag \ maxr + 1); ")"
  Printer.Print
  
  msup = Printer.CurrentY + 1
  
If tb.RecordCount - righe < maxr Then maxr = tb.RecordCount - righe
  Printer.CurrentY = msup + 0.04
  Printer.Print Tab(colx); sHeader
  Printer.CurrentY = Printer.CurrentY + 0.04
  Printer.Print
  
For rec = 1 To maxr
   riga = ""

For i = 0 To tb.Fields.Count - 1
  riga = riga + bar + pad1(valida(tb.Fields(i)), aColWidth(i))
Next i

Printer.CurrentY = Printer.CurrentY + 0.04
  Printer.Print Tab(colx); riga
  righe = righe + 1
  tb.MoveNext
Next rec

Printer.Line (msin, msup)-Step(Len(sHeader), 1), , B

For i = 1 To maxr
  Printer.Line (msin, msup + i + 1)-Step(Len(sHeader), 1), , B
Next i

For i = 0 To tb.Fields.Count - 2
  Printer.Line (msin + aPosVLine(i), msup)-Step(0, maxr + 2)
Next i

Printer.NewPage
  Next pag
  
Printer.EndDoc

tb.Close
db.Close
Set tb = Nothing
Set db = Nothing
Set ws = Nothing
  Screen.MousePointer = vbDefault

End Sub