谁能解释一下这个vb程序

来源:百度知道 编辑:UC知道 时间:2024/05/10 22:25:14
Private Sub Command1_Click()

Dim sfilename As String

On Error GoTo x1:
If File1.ListCount <= 0 Then '文件列表框如果没有图片,取消操作
Exit Sub
End If
jb = jb + 1
File1.ListIndex = jb
If Right(File1.Path, 1) <> "\" Then '判断选定文件
sfilename = File1.Path & "\" & File1.FileName
Else
sfilename = File1.Path & File1.FileName
End If
Picture2.Picture = LoadPicture(sfilename) '导入选定图片显示
x1:
End Sub
我对这个程序有点不明白,哪位高手能助我一臂之力呢?
If Right(File1.Path, 1) <> "\" Then '判断选定文件
sfilename = File1.Path & "\" & File1.FileName
这里是什么意思

其实就是多了一个判断,
比如文件路径是 C:\Windows\a.bmp

文件名是 a.bmp 吧,
如果路径是 "C:\Windows" ,那你就要多加一个 "\"
如果是 "C:\Windows\",那就直接拼到一起就行了

不知道楼主哪里不明白哦
sfilename为要导入图片的路径

主要就是file控件的使用了