我必须纠正一些用VB6制作的程序的麻烦。
当我尝试以XPS类型打印文件然后关闭文件夹选择框时,程序会给我一个“运行时错误482”。
所以我决定弄错:
On Error GoTo Error_Handler
它适用于Windows XP,运行时错误不会出现,但在Windows 7(64位)下,程序没有响应。
我不知道为什么它在一边工作而不在另一边
我尝试在Windows 7上运行Windows XP兼容性的软件,但它不起作用
Public Sub Print_All_Click()
Dim prntLePrinter As Printer
Dim iI As Integer
For Each prntLePrinter In Printers
iI = iI + 1
Next
On Error GoTo Error_Handler
If (iI > 0) Then
MousePointer = vbHourglass
'CD Référence d'échelle pour l'imprimante
Printer.ScaleHeight = 100
Printer.ScaleWidth = 100
'CD Configuration de la font
Printer.FontName = "Arial"
Printer.FontSize = 8
Printer.FontBold = False
Printer.FontItalic = False
Printer.FontUnderline = False
Printer.FontStrikethru = False
Printer.FontTransparent = True
Printer.Font.Charset = 0
If g_nbSessions = 1 Then 'Mode NORMAL
PrintHEADER
PrintGeneral
PrintExceedances
PrintEpc
PrintAlarms
PrintMfdPages
PrintEndReport
Else 'Mode CUMUL
PrintHEADERCumul
PrintCUMUL
PrintEndReportCumul
End If
Printer.EndDoc
MousePointer = vbDefault
Else
MsgBox "No printer installed !", vbOKOnly, Frm_Main.Caption
End If
Error_Handler:
If MousePointer <> vbDefault Then
MousePointer = vbDefault
End If
End Sub
答案 0 :(得分:0)
我找到了解决方案。
我必须使用“Clear”在处理错误后明确清除Err对象,然后当我想关闭“选择文件夹框”时,程序在Windows XP和Windows 7上正确关闭它。
因此,如果您使用On Error GoTo Error_Handler
不要忘记使用:
Error_Handler:
并且:
Err.Clear
我的代码现在:
Public Sub Print_All_Click()
Dim prntLePrinter As Printer
Dim iI As Integer
For Each prntLePrinter In Printers
iI = iI + 1
Next
On Error GoTo Error_Handler
If (iI > 0) Then
MousePointer = vbHourglass
'CD Référence d'échelle pour l'imprimante
Printer.ScaleHeight = 100
Printer.ScaleWidth = 100
'CD Configuration de la font
Printer.FontName = "Arial"
Printer.FontSize = 8
Printer.FontBold = False
Printer.FontItalic = False
Printer.FontUnderline = False
Printer.FontStrikethru = False
Printer.FontTransparent = True
Printer.Font.Charset = 0
If g_nbSessions = 1 Then 'Mode NORMAL
PrintHEADER
PrintGeneral
PrintExceedances
PrintEpc
PrintAlarms
PrintMfdPages
PrintEndReport
Else 'Mode CUMUL
PrintHEADERCumul
PrintCUMUL
PrintEndReportCumul
End If
Printer.EndDoc
MousePointer = vbDefault
Else
MsgBox "No printer installed !", vbOKOnly, Frm_Main.Caption
End If
Error_Handler:
Err.Clear
If MousePointer <> vbDefault Then
MousePointer = vbDefault
End If
End Sub