简体   繁体   中英

Windows application closes after printing

I created a POS application with printing capability. The application works well and can also print. The only problem is that, it closes after printing. I have settings defined at user scope. When I disable printing, everything works perfectly. Any idea what could be the cause? My printing code below:

 Sub PrintSlip(ByVal tender As Decimal, ByVal change As Decimal)
    Dim P As New PrinterClass(Application.StartupPath)
    With P
        'Printing Logo
        .RTL = False
        .PrintLogo()


        'Printing Title
        .FeedPaper(4)
        .AlignCenter()
        .BigFont()
        .Bold = True
        .WriteLine("Sales Receipt")
        .Bold = False
        .GotoSixth(6)
        .WriteLine(My.Settings.TransNo)
        'Printing Date
        .GotoSixth(1)
        .NormalFont()
        .WriteChars("Date:")
        .WriteLine(DateTime.Now.ToString)
        .DrawLine()
        .GotoSixth(1)
        .WriteChars("Store:")
        .GotoSixth(2)
        .WriteChars(My.Settings.StoreName)
        .GotoSixth(3)
        .WriteChars("VAT No.")
        .GotoSixth(4)
        .WriteChars(My.Settings.VatNo)
        .GotoSixth(5)
        .WriteChars("Cashier:")
        .GotoSixth(6)
        .WriteChars(My.Settings.User)
        .WriteLine("")
        .GotoSixth(1)
        .DrawLine()
        .FeedPaper(2)

        'Printing Header
        .GotoSixth(1)
        .WriteChars("#")
        .GotoSixth(2)
        .WriteChars("Description")
        .GotoSixth(5)
        .WriteChars("QTY")
        .GotoSixth(6)
        .WriteChars("Sub Total")
        .WriteLine("")
        .DrawLine()
        '.FeedPaper(1)

        'Printing Items

        Dim i As Integer
        For i = 1 To Form1.DataGridView1.RowCount - 1
            .GotoSixth(1)
            .WriteChars(i)
            .GotoSixth(2)
            .WriteChars(Form1.DataGridView1.Rows(i - 1).Cells(2).Value)
            .GotoSixth(5)
            .WriteChars(Form1.DataGridView1.Rows(i - 1).Cells(3).Value)
            .GotoSixth(6)
            .WriteChars(My.Settings.currency & Form1.DataGridView1.Rows(i - 1).Cells(5).Value)
            .WriteLine("")
        Next

        'Printing Totals
        .NormalFont()
        .DrawLine()
        .GotoSixth(5)
        .WriteChars("TOTAL Inc VAT")
        .GotoSixth(6)
        .WriteChars(My.Settings.currency & Math.Round(My.Settings.Cash, 2))
        .WriteLine("")
        .GotoSixth(5)
        .WriteChars("VAT @ " & My.Settings.vat & "%")
        .GotoSixth(6)
        .WriteChars(My.Settings.currency & Math.Round(My.Settings.Cash * (My.Settings.vat / 100), 2))
        .WriteLine("")
        .GotoSixth(5)
        .WriteChars("Cash")
        .GotoSixth(6)
        .WriteChars(My.Settings.currency & Math.Round(tender, 2))

        .WriteLine("")
        .GotoSixth(5)
        .WriteChars("Change")
        .GotoSixth(6)
        .WriteChars(My.Settings.currency & Math.Round(change, 2))

        .WriteLine("")
        .DrawLine()
        .GotoSixth(1)
        .WriteChars(My.Settings.EndSlip)



        .CutPaper()

        'Ending the session
        .EndDoc()
    End With
    End
End Sub

You have End placed after End With , which will force the application to stop. Removing this should clear up your issue!

From the MSDN reference :

You can place the End statement anywhere in a procedure to force the entire application to stop running. End closes any files opened with an Open statement and clears all the application's variables. The application closes as soon as there are no other programs holding references to its objects and none of its code is running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM