首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

VB转VB.NET打印有关问题

2012-03-25 
VB转VB.NET打印问题VB.NET codeVB。NET中在CLASS中定义一个Private outFile As FileStreamPrivate hPortP A

VB转VB.NET打印问题

VB.NET code
VB。NET中在CLASS中定义一个Private outFile As FileStreamPrivate hPortP As IntPtr    Public Sub OpenPort(ByVal pPrinterPort As String)        hPort = CreateFile(pPrinterPort, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)        hPortP = New IntPtr(hPort)         outFile = New FileStream(hPortP, FileAccess.Write)     End Sub    Public Sub PrintLine(ByVal pLine As String)        Dim fileWriter As New StreamWriter(outFile)        fileWriter.Write(pLine)        fileWriter.Flush()        fileWriter.Close()    End Sub    Public Sub ClosePort()        FileClose(iPort)        outFile.Close()        retval = CloseHandle(hPort)    End Sub在程序中调用打印命令OpenPort("COM1")PrintLine("")PrintLine("ABC")  '每次执行到这一步就出错。


[解决办法]
fileWriter.Close() 先不要关闭。写完所有在关闭。
--
或者直接执行:
OpenPort("COM1")
PrintLine("ABC")
--
我打印少用你这种打印法。
[解决办法]
Dim Fileinfo As New FileInfo(filename)
Dim fileWriter As StreamWriter=fileinfo.CreateText()
'若要覆寫使用AppendText()
fileWriter.Write(pLine)
'若是寫一行後跳行使用WriteLine(pLine)
fileWriter.Flush()
fileWriter.Close()

[解决办法]
fileWriter.Close() 先不要关闭。

执行完在close
[解决办法]
就是这样 先不要关闭filewriter

热点排行