我用了一位帅哥的函数想判断文件是以doc还是以dwg ,jpg文件,我在一个小程序中用的是Data控件与数据库绑定,DBlist再与数据库中的文件存放地址绑定,实现打开文件,可以用这个函数,一点问题也没有
Private Function ExtractFileName(ByVal PathName As String) As String
Dim str_Pos As Integer
For str_Pos = Len(PathName) To 1 Step -1
If Mid$(PathName, str_Pos, 1) = "." Then
Exit For
End If
Next str_Pos
ExtractFileName = Right$(PathName, Len(PathName) - str_Pos)
End Function
但我在另外一个程序中,用的是ADODC,用textBox与地址这个字段绑定,但运行却碰到如我标题所说的错误,就出现在Right$上,什么原因啊
Private Function ExtractFileName(ByVal PathName As String) As String
Dim str_Pos As Integer
For str_Pos = Len(PathName) To 1 Step -1
If Mid$(PathName, str_Pos, 1) = "." Then
Exit For
End If
Next str_Pos
ExtractFileName = Right$(PathName, Len(PathName) - str_Pos)
End Function
但我在另外一个程序中,用的是ADODC,用textBox与地址这个字段绑定,但运行却碰到如我标题所说的错误,就出现在Right$上,什么原因啊
假如Private Sub Command1_Click()
MsgBox Right$("lxcc", -1)
End Sub参数是不匹配的!
?Len(PathName)
0
?Len(PathName)-str_Pos
0
不知道该怎么改啊
Dim str_Pos As Integer
For str_Pos = Len(PathName) To 1 Step -1
If Mid$(PathName, str_Pos, 1) = "." Then
Exit For
End If
Next str_Pos
ExtractFileName = Right$(PathName, Len(PathName) - str_Pos)
End Function
这个是获的扩展名吧,你用instrrev多好
Dim intDotPos As Integer '右边开边最近的点号位置
dim intExLen as integer
dim strReturn as string strReturn=""
intDotPos=instrrev(PathName,".")
if intDotPos>0 then
intExLen=len(PathName)-intDotPos
strReturn=right$(PathName,intExLen)
end if
ExtractFileName=strReturn
End Function