Upgrade 'print' from vb6 to vb.net

Joined
Mar 12, 2007
Messages
11
Programming Experience
Beginner
Hi, im currently upgrading a system from vb6 to vb.net with no experience in vb.net at all. Thus, i have no idea on how to convert this vb6 code to vb.net. Ive tried looking into articles and forums regarding printing in vb.net, but i still cant seems to understand how to modify this.

Can anyone please help? Your help is very much appreciated.

Many thanks.

Below are my lines of coding :

VB.NET:
Private Sub WriteLine(vCount)
'Write file record
vXBLNR = Left(vKOSTL, 1) & "SV" & Mid(ctlBUDAT, 7, 2) & _
Mid(vHexMth, Val(Mid(ctlBUDAT, 3, 2)), 1) & Format(vCount, "000") 'YYH
Print #1, ctlBLDAT; ctlBLART; ctlBUKRS; ctlBUDAT; ctlMONAT; vXBLNR _
; ctlNEWBS; vCustCode; Format(vAmount, "0000000000.00") _
; ctlNEWBS1; ctlHKONT; vKOSTL; ctlAUFNR; ctlNAR1; ctlNAR2 _
; vNar3; vNar4
'Print report
If Printer.CurrentY >= 14400 Then
Printer.NewPage
WriteHeader
End If
Printer.Print , vCount, vKOSTL, vCustCode, vName
Printer.Print , , vXBLNR, ctlNAR1, , Format(vAmount, "000.00")
Printer.Print , , , , ctlNAR2
Printer.Print , , , , vNar3
If Len(Trim(vNar4)) > 0 Then
Printer.Print , , , , vNar4
End If
 
-------------------------------------------------------------
 
Private Sub WriteHeader()
Dim t As String
Dim p As Integer
Printer.FontSize = 10
t = "Userid: " & gUserID
Printer.CurrentY = 1440
Printer.CurrentX = 1440
Printer.Print t;
t = "Carlsberg Marketing Sdn. Bhd."
p = (Printer.Width - Printer.TextWidth(t)) / 2
Printer.CurrentX = p
Printer.Print t;
Printer.CurrentX = Printer.Width - 2880
Printer.Print Format(Now, "short date");
Printer.Print " " & Format(Now, "HH:MM")
t = "Wholesalers' Van Advertisement Credit Notes Listing"
p = (Printer.Width - Printer.TextWidth(t)) / 2
Printer.CurrentX = p
Printer.Print t;
Printer.CurrentX = Printer.Width - 2880
Printer.Print "Page No. " & Printer.Page
Printer.Print
Printer.Print , "No.", "S/Office", "Customer ", "Name"
Printer.Print , , "CN No.", , "Narration", , , "Amount"
Printer.Print
End Sub
Printer.Print
End Sub
 
Last edited by a moderator:
Printing with .Net is done through PrintDocument class (just add one to form if you like) and its PrintPage event. There you draw what is to be printed, for example text is drawn with the graphics DrawString method.
VB.NET:
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
    Handles PrintDocument1.PrintPage
        e.Graphics.DrawString("some text", Me.Font, Brushes.Black, 10, 10)
    End Sub
Please use the code boxes when posting code blocks, see my signature for more info about this if you need it.
 
Back
Top