Windows 打印后应用程序关闭
Windows application closes after printing
我创建了一个具有打印功能的 POS 应用程序。该应用程序运行良好,还可以打印。唯一的问题是,它在打印后关闭。我在用户范围内定义了设置。当我禁用打印时,一切正常。知道可能是什么原因吗?我的打印代码如下:
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
您在 End With
之后放置了 End
,这将强制应用程序停止。删除它应该可以解决您的问题!
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.
我创建了一个具有打印功能的 POS 应用程序。该应用程序运行良好,还可以打印。唯一的问题是,它在打印后关闭。我在用户范围内定义了设置。当我禁用打印时,一切正常。知道可能是什么原因吗?我的打印代码如下:
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
您在 End With
之后放置了 End
,这将强制应用程序停止。删除它应该可以解决您的问题!
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.