VB6打印模块适用于Win98,但不适用于Win7
VB6打印模块适用于Win98,但不适用于Win7。这部分文字可能有问题,请给我解决方案。提前谢谢 注意:错误消息是无法分配作业IDVB6打印模块适用于Win98,但不适用于Win7,vb6,Vb6,VB6打印模块适用于Win98,但不适用于Win7。这部分文字可能有问题,请给我解决方案。提前谢谢 注意:错误消息是无法分配作业ID 这是用于调用print函数的完整代码。同样的代码在Win98中运行良好,但在Win7中失败。请给我一个解决方案。我不知道你在问什么。你能定义不工作吗?如果有错误,请给出错误消息。如果您尚未发布所有相关代码,请这样做。例如,如果AddJob返回的不是1,请显示AddJob的代码。您好,谢谢您的回复。刚才我用完整的代码编辑了这个问题。错误消息是无法分配作业ID!要有人
这是用于调用print函数的完整代码。同样的代码在Win98中运行良好,但在Win7中失败。请给我一个解决方案。我不知道你在问什么。你能定义不工作吗?如果有错误,请给出错误消息。如果您尚未发布所有相关代码,请这样做。例如,如果AddJob返回的不是1,请显示AddJob的代码。您好,谢谢您的回复。刚才我用完整的代码编辑了这个问题。错误消息是无法分配作业ID!要有人回答,你需要说它是如何不起作用的,而不是它不起作用。它会抛出错误吗?如果是,电话号码和留言是什么?通过在调试器中单步执行代码来确定哪一行失败了吗?添加任何有助于我们确定问题的其他内容。感谢您的建议,请注意:错误消息为Cannot assign JobID!AddJob的功能是什么?尝试AddJob后成功的价值是什么?
Function NSPrintFile(PrinterName As String, FileToPrint As String, delAfterPrint As Long) As Long
Dim I As Long
Dim Success As Long, phPrinter As Long, Level As Long
Dim cdBuf As Long, pcbNeeded As Long, JobId As Long
Dim pPrinterName As String, strJobId As String, strSpoolFile As String
Dim pDefault As PRINTER_DEFAULTS
Dim pData As ADDJOB_INFO_1, StartPos As Integer, tmpStartPos As Integer
pPrinterName = Printer.DeviceName
Success = OpenPrinter(pPrinterName, phPrinter, pDefault)
If Success <> 1 Then
MsgBox "No Printers are installed or Cannot access the Printer !", vbExclamation, "NSPrint"
NSPrintFile = False
Exit Function
End If
Level = 1
cdBuf = 64
pcbNeeded = 0
pData.Path = String(64, " ")
Success = AddJob(phPrinter, Level, pData, cdBuf, pcbNeeded)
If Success <> 1 Then
MsgBox "Cannot assign JobID !", vbExclamation, "NSPrint"
NSPrintFile = False
Exit Function
End If
strJobId = Left(pData.Path, 4)
JobId = Val(Asc(Mid(strJobId, 1, 1))) * 2 ^ 0
JobId = JobId + Val(Asc(Mid(strJobId, 2, 1))) * 2 ^ 8
JobId = JobId + Val(Asc(Mid(strJobId, 3, 1))) * 2 ^ 16
JobId = JobId + Val(Asc(Mid(strJobId, 4, 1))) * 2 ^ 24
tmpStartPos = 0
Do Until tmpStartPos = 0 And StartPos <> 0
tmpStartPos = tmpStartPos + 1
tmpStartPos = InStr(tmpStartPos, pData.Path, "C:\")
If tmpStartPos = 0 Then Exit Do
StartPos = tmpStartPos
Loop
strSpoolFile = Mid(pData.Path, StartPos)
' For i = 5 To 64
' If Asc(Mid(pData.Path, i, 1)) <> 0 Then
' strSpoolFile = strSpoolFile & Mid(pData.Path, i, 1)
' End If
' Next
On Error Resume Next
FileCopy FileToPrint, strSpoolFile
If Err.Number <> 0 Then
MsgBox Err.Number & " : " & Err.Description, vbExclamation, "NSPrint"
NSPrintFile = False
Exit Function
End If
Success = ScheduleJob(phPrinter, JobId)
If Success <> 1 Then
MsgBox "Cannot Spool the Printer JobID !", vbExclamation, "NSPrint"
NSPrintFile = False
Exit Function
End If
Success = ClosePrinter(phPrinter)
If Success <> 1 Then
MsgBox "Cannot close the Printer !", vbExclamation, "NSPrint"
NSPrintFile = False
Exit Function
End If
If delAfterPrint = True Then Kill FileToPrint
NSPrintFile = True
End Function