2016-02-19 17 views
1

我想在图片框中显示选定的图片。以下是代码:其他如果不在Visual Basic中工作6

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.以下是输出:

enter image description here

请让我知道在上面的代码中的错误。

+0

需要更多的信息。哪一行是抛出错误?如果File1_Click里面有一个你的错误管理是无效的,因为它可以让你在任何情况下得到'Picture1.Picture ...' – user3598756

+0

如果一起写入 – Kathara

+0

如果这是VB6,为什么是VBA标签? VBA和VB6不尽相同,即使它们共享(某些)功能。这是什么?如果是VB6,你想更改标签,以便你可以确定合适的人看到这个...... –

回答

1

你平时把你的错误处理程序之前的代码可能会抛出错误吗?我无法通过我自己的简单案例来复制此内容,但此代码的结构似乎有些可疑。你也有一个没有循环的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 
+0

试过上面的代码,仍然是同一个问题 – user3382203

+0

哪条线提高了错误? –

+0

Dir1.Path = Drive1.Drive – user3382203