VB中如何将FileListBox中选定文件的不带后缀的文件名赋给一个变量

来源:百度知道 编辑:UC知道 时间:2024/05/19 08:45:44
在窗体上放了三个控件
DriveListBox
DriListBox
FileListBox
对应程序如下

Private Sub Drive1_Change()
Form1.Dir1.Path = Form1.Drive1.Drive
End Sub

Private Sub Dir1_Change()
Form1.File1.Path = Form1.Dir1.Path
End Sub

Private Sub File1_Click()
DBPath = Form1.File1.Path
End Sub

这样得到的只是文件的地址。

如何才能得到的选定文件的不带后缀的文件名?是把倒数第二句改掉,还是重新写几句别的代码。

我需要具体的代码,谢谢各位!

Private Sub File1_Click()
n=InStrRev(File1.FileName, ".") - 1)
DBPath = iif(n>0,Left(File1.FileName,n-1),File1.FileName)
End Sub

Private Sub Drive1_Change()
Form1.Dir1.Path = Form1.Drive1.Drive
End Sub

Private Sub Dir1_Change()
Form1.File1.Path = Form1.Dir1.Path
End Sub

Private Sub File1_Click()
if instr(File1.FileName,".")=0 then
dbpath=File1.FileName
else
dbpath = Left(File1.FileName, InStr(Form1.File1.FileName, ".") - 1)
end if
MsgBox dbpath
End Sub

Private Sub Drive1_Change()
Form1.Dir1.Path = Form1.Drive1.Drive
End Sub

Private Sub Dir1_Change()
Form1.File1.Path = Form1.Dir1.Path
End Sub

Private Sub File1_Click()
Dim DBPath$
DBPath = File1.Path & "\" & Left(File1.FileName, InStrR