Private Sub RelocatableSourceToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RelocatableSourceToolStripMenuItem.Click
Const LinesPerPage As Integer = 42
Dim Line As Integer
Dim Page As Integer
Dim AssembledLine As String
Dim temp As Integer
Dim temp2 As String
PrintBufferIndex = 0
ReDim PrintBuffer2(PrintBufferIndex)
For Line = 0 To rtObjectCode.Lines.Count - 1
Page = Int(Line / LinesPerPage)
If Page > PrintBufferIndex Then
PrintBufferIndex += 1
ReDim Preserve PrintBuffer2(PrintBufferIndex)
End If
AssembledLine = rtObjectCode.Lines(Line)
'If the line starts with four hexadecimal digits
If Regex.Matches(AssembledLine, "\A[0-9A-F]{4}").Count > 0 Then
'Convert to decimal
temp = Convert.ToInt32(AssembledLine.Substring(0, 4), 16) + My.Settings.Offset
temp2 = temp.ToString("X4")
PrintBuffer2(PrintBufferIndex) &= temp2 & "-" & AssembledLine & vbCrLf
Else
PrintBuffer2(PrintBufferIndex) &= " " & AssembledLine & vbCrLf
End If
Next
Dim Result As DialogResult
If FileNameNAM.Length > 0 Then 'If a NAM directive was found.
SaveFilename = FileNameNAM
Else
MsgBox("You need a NAM directive." & vbCrLf & vbCrLf & "Try again.",, "Missing filename for printing")
Exit Sub
End If
With PrintDialog1
.PrintToFile = True
.PrinterSettings.PrintFileName = SaveFilename
End With
Result = PrintDialog1.ShowDialog
PrintIndex = 0
With PrintDocument2
.PrinterSettings = PrintDialog1.PrinterSettings
.DocumentName = SaveFilename
.OriginAtMargins = False 'Margins are not respected.
.DefaultPageSettings.Landscape = True 'Makes the first page and following portrait.
.Print() 'Prints the page(s).
End With
End Sub
Private Sub PrintDocument2_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
Dim MyFont As Font = New Font("Courier New", 10)
Dim MyFormat As StringFormat = New StringFormat()
Dim MyTabs() As Single = {100, 30, 30, 30, 30, 30, 100}
MyFormat.SetTabStops(0, MyTabs) 'Set tabs.
e.PageSettings.Landscape = True
e.Graphics.DrawString(PrintBuffer2(PrintIndex), MyFont, Brushes.Black, 50, 90, MyFormat) 'Code data.
PrintIndex += 1
If PrintIndex < PrintBuffer2.Length Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub