请高手帮忙解释以下VB代码的意思!!帮忙注释一下,谢谢拉!
rivateSubDrive1_Change()OnErrorGoToDriErrDir1.Path=Drive1.DriveExitSubDriErr:IfErr.Nu...
rivate Sub Drive1_Change()
On Error GoTo DriErr
Dir1.Path = Drive1.Drive
Exit Sub
DriErr:
If Err.Number = 68 Then
If MsgBox("请问要重试还是取消?", vbRetryCancel + vbCritical, "硬盘不存在或光驱没有插入磁盘!") = vbRetry Then
Resume 0
Else
Drive1.Drive = "C:"
Resume Next
End If
End If
End Sub
Private Sub File1_Click()
Dim picFile As String
If Right(Dir1.Path, 1) = "\" Then
picFile = Dir1.Path + File1.FileName
Else
picFile = Dir1.Path + "\" + File1.FileName
End If
Form1.Picture1.Picture = LoadPicture(picFile)
Form1.Text1.Text = picFile
Dim p As Picture
Set p = Form1.Picture1.Picture
Form1.Picture1.PaintPicture p, 0, 0, Form1.Picture1.Width, Form1.Picture1.Height
End Sub 展开
On Error GoTo DriErr
Dir1.Path = Drive1.Drive
Exit Sub
DriErr:
If Err.Number = 68 Then
If MsgBox("请问要重试还是取消?", vbRetryCancel + vbCritical, "硬盘不存在或光驱没有插入磁盘!") = vbRetry Then
Resume 0
Else
Drive1.Drive = "C:"
Resume Next
End If
End If
End Sub
Private Sub File1_Click()
Dim picFile As String
If Right(Dir1.Path, 1) = "\" Then
picFile = Dir1.Path + File1.FileName
Else
picFile = Dir1.Path + "\" + File1.FileName
End If
Form1.Picture1.Picture = LoadPicture(picFile)
Form1.Text1.Text = picFile
Dim p As Picture
Set p = Form1.Picture1.Picture
Form1.Picture1.PaintPicture p, 0, 0, Form1.Picture1.Width, Form1.Picture1.Height
End Sub 展开
2个回答
展开全部
rivate Sub Drive1_Change() 'Drive1发生改变触发
On Error GoTo DriErr '当出错时跳到 DriErr
Dir1.Path = Drive1.Drive 'Dir1路径为Drive1选择的盘符路径
Exit Sub
DriErr: '出错标记
If Err.Number = 68 Then '如果返回出错代号为68时
If MsgBox("请问要重试还是取消?", vbRetryCancel + vbCritical, "硬盘不存在或光驱没有插入磁盘!") = vbRetry Then '弹出提示框
Resume 0
Else
Drive1.Drive = "C:" '
Resume Next
End If
End If
End Sub
Private Sub File1_Click()
Dim picFile As String '定义变量
If Right(Dir1.Path, 1) = "\" Then
picFile = Dir1.Path + File1.FileName
Else
picFile = Dir1.Path + "\" + File1.FileName'变量值为Dir1中选中的文件路径加文件名
End If
Form1.Picture1.Picture = LoadPicture(picFile) '将得到的文件路径下的文件载入Picture1控件内
Form1.Text1.Text = picFile '在Text中显示文件路径
Dim p As Picture
Set p = Form1.Picture1.Picture
Form1.Picture1.PaintPicture p, 0, 0, Form1.Picture1.Width, Form1.Picture1.Height '设置控件
End Sub
On Error GoTo DriErr '当出错时跳到 DriErr
Dir1.Path = Drive1.Drive 'Dir1路径为Drive1选择的盘符路径
Exit Sub
DriErr: '出错标记
If Err.Number = 68 Then '如果返回出错代号为68时
If MsgBox("请问要重试还是取消?", vbRetryCancel + vbCritical, "硬盘不存在或光驱没有插入磁盘!") = vbRetry Then '弹出提示框
Resume 0
Else
Drive1.Drive = "C:" '
Resume Next
End If
End If
End Sub
Private Sub File1_Click()
Dim picFile As String '定义变量
If Right(Dir1.Path, 1) = "\" Then
picFile = Dir1.Path + File1.FileName
Else
picFile = Dir1.Path + "\" + File1.FileName'变量值为Dir1中选中的文件路径加文件名
End If
Form1.Picture1.Picture = LoadPicture(picFile) '将得到的文件路径下的文件载入Picture1控件内
Form1.Text1.Text = picFile '在Text中显示文件路径
Dim p As Picture
Set p = Form1.Picture1.Picture
Form1.Picture1.PaintPicture p, 0, 0, Form1.Picture1.Width, Form1.Picture1.Height '设置控件
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询