在 Windows 7 上无法在 VB6 中出现错误,而在 Windows Xp 上可以
Can't get an error in VB6 on Windows 7 while I can on Windows Xp
我必须更正一个用 VB6 编写的程序的一些问题。
当我尝试打印 XPS 类型的文件然后关闭文件夹选择框时,程序会给我一个 "Run time error 482"。
所以我决定用这个来解决错误:
On Error GoTo Error_Handler
在Windows XP上运行,运行时间错误没有出现,但在Windows7(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
我找到了解决办法。
我必须在处理错误后使用 "Clear" 明确清除 Err 对象,然后当我想关闭 "selection folder box" 时,程序会在 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
我必须更正一个用 VB6 编写的程序的一些问题。
当我尝试打印 XPS 类型的文件然后关闭文件夹选择框时,程序会给我一个 "Run time error 482"。
所以我决定用这个来解决错误:
On Error GoTo Error_Handler
在Windows XP上运行,运行时间错误没有出现,但在Windows7(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
我找到了解决办法。
我必须在处理错误后使用 "Clear" 明确清除 Err 对象,然后当我想关闭 "selection folder box" 时,程序会在 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