VB中如何将FileListBox中选定文件的不带后缀的文件名赋给一个变量
在窗体上放了三个控件DriveListBoxDriListBoxFileListBox对应程序如下PrivateSubDrive1_Change()Form1.Dir1....
在窗体上放了三个控件
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
这样得到的只是文件的地址。
如何才能得到的选定文件的不带后缀的文件名?是把倒数第二句改掉,还是重新写几句别的代码。
我需要具体的代码,谢谢各位! 展开
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
这样得到的只是文件的地址。
如何才能得到的选定文件的不带后缀的文件名?是把倒数第二句改掉,还是重新写几句别的代码。
我需要具体的代码,谢谢各位! 展开
11个回答
展开全部
改倒数第二句即可
路径 完整的文件名:
dbpath = Form1.File1.Path & "\" & Form1.File1.FileName
只要不带扩展名的文件名:(不带路径,一般扩展名是3个字符,前加一个“.”符号,共四个,从左取 len(Form1.File1.FileName-4)个字符就是你要的结果
如下: dbpath = Left(Form1.File1.FileName, Len(Form1.File1.FileName) - 4)
路径 完整的文件名:
dbpath = Form1.File1.Path & "\" & Form1.File1.FileName
只要不带扩展名的文件名:(不带路径,一般扩展名是3个字符,前加一个“.”符号,共四个,从左取 len(Form1.File1.FileName-4)个字符就是你要的结果
如下: dbpath = Left(Form1.File1.FileName, Len(Form1.File1.FileName) - 4)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'只要修改下面代码就可以了。
Private Sub File1_Click()
dim s as string,i as integer
s=File1.List (File1.ListIndex)
i=instrrev(s,".")
DBPath =iif(i>0, left(s,i-1),s)
End Sub
Private Sub File1_Click()
dim s as string,i as integer
s=File1.List (File1.ListIndex)
i=instrrev(s,".")
DBPath =iif(i>0, left(s,i-1),s)
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
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 FileName As String, P As Integer
FileName = File1.List(File1.ListIndex)
P = InStrRev(FileName, ".")
DBPath = IIf(P > 0, Left(FileName, P - 1), FileName)
End Sub
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 FileName As String, P As Integer
FileName = File1.List(File1.ListIndex)
P = InStrRev(FileName, ".")
DBPath = IIf(P > 0, Left(FileName, P - 1), 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()
Dim DBPath$
DBPath = File1.Path & "\" & Left(File1.FileName, InStrRev(File1.FileName, ".") - 1)
MsgBox DBPath
End Sub
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, InStrRev(File1.FileName, ".") - 1)
MsgBox DBPath
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询