Vb6 否则,如果不在visual basic 6中工作
我想在图片框中显示所选图片。代码如下:Vb6 否则,如果不在visual basic 6中工作,vb6,Vb6,我想在图片框中显示所选图片。代码如下: Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End Sub Private Sub Dir1_Change() File1.Path = Dir1.Path End Sub Private Sub File1_Click() On Error GoTo lab lab: If Err.Number = 481 Then MsgBox ("Please select a valid P
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub File1_Click()
On Error GoTo lab
lab:
If Err.Number = 481 Then
MsgBox ("Please select a valid Picture")
Else
If Err.Number = 68 Then
MsgBox ("Device not ready")
End If
End If
Resume Next
Picture1.Picture = LoadPicture(File1.Path + "\" + File1.FileName)
End Sub
案例481工作得很好,但第二个案例错误68根本不起作用。它显示运行时错误68。输出结果如下:
请让我知道上述代码中的错误。您是否通常将错误处理程序放在可能引发错误的代码之前?我自己无法用一个简单的案例来复制这一点,但这段代码的结构似乎令人怀疑。您还有一个不带循环的
Resume Next
。请尝试以下方法:
Private Sub File1_Click()
On Error GoTo lab
Picture1.Picture = LoadPicture(File1.Path + "\" + File1.FileName)
Exit Sub
lab:
Select Case Err.Number
Case 481 Then
MsgBox ("Please select a valid Picture")
Case 68 Then
MsgBox ("Device not ready")
End Select
End Sub
听起来您可能需要在其他过程中使用其他错误处理程序,例如:
Private Sub Dir1_Change()
On Error Resume Next
File1.Path = Dir1.Path
If Err.Number = 0 Then Exit Sub
Select Case Err.Number
Case 68
Msgbox ("Device not ready")
Case Else
MsgBox ("Error " & Err.NUmber) '# Modify as needed...
End Select
End Sub
Private Sub Drive1_Change()
On Error Resume Next
Dir1.Path = Drive1.Drive
If Err.Number = 0 Then Exit Sub
Select Case Err.Number
Case 68
Msgbox ("Device not ready")
Case Else
MsgBox ("Error " & Err.NUmber) '# Modify as needed...
End Select
End Sub
需要更多信息。哪一行抛出错误?如果文件中有一个文件1\u单击您的错误管理无效,因为它可以让您获得“Picture1.Picture…”在任何情况下,如果它是一起写入的,那么为什么要使用VBA标记?VBA和VB6不一样,尽管它们共享(某些)功能。是哪一个?如果是VB6,您希望更改标记,以便确保正确的人看到此…Dir1.Path=Drive1.Drive1。当然,在您最初的问题中知道这一点会很有帮助。。。您在该过程中没有任何错误处理。您的错误处理程序仅在
文件1\u Click
事件过程中是本地的。嗯。。。我的错误。。。我知道了。无论如何,谢谢。我在每个过程中都用本地错误处理程序修改了答案。