Latihan 10 Visual Basic - Error Handle
Private Sub Command1_Click()
Dim FileName As String
Dim ErrMsg As String
Dim Ask As VbMsgBoxResult
On Error GoTo AdaError
Awal:
Image1.Picture = Nothing
FileName = InputBox("Ketikkan path dan nama file gambar :", "Open Picture File", FileName)
If FileName <> "" Then
Image1.Picture = LoadPicture(FileName)
End If
Exit Sub
AdaError:
Select Case Err.Number
Case 53
ErrMsg = "File [" & FileName & "] tidak ada !"
Case 71
ErrMsg = "Disket belum dimasukkan !"
Case Else
ErrMsg = Err.Description
End Select
Ask = MsgBox(ErrMsg, vbCritical + vbRetryCancel, Me.Caption)
Select Case Ask
Case vbRetry
If Err.Number = 53 Then Resume Awal Else Resume
Case vbCancel
Resume Next
End Select
End Sub
0 komentar:
Posting Komentar