请问在VB中 if right(file1.path,10)<>"/"then

来源:百度知道 编辑:UC知道 时间:2024/05/30 00:19:25
请问在VB中
if right(file1.path,10)<>"/"then
fileremove=file1.path + "/"+file1.name
else
fileremove=file1.path+file.filname
end if
这段代码是什么意思

如果file1.path里没包含"/",合成文件名时加上"/"。比如c:/aa.txt

'如果file1的最右边字符不为"/"
if right(file1.path,10)<>"/"then

'fileremove变量的内容为file1.path中的路径加"/",加文件名
fileremove=file1.path + "/"+file1.name

else

'否则,fileremove变量的内容就等于file1.path中的内容
fileremove=file1.path+file.filname

end if

这句话是用来获取file1控件中的完整路径和文件名的

我想作者的意思是:
如果文件路径的倒数第10个字符不是"/"那么自动添加一个"/" 如果是“/”就不需要添加/

其实这个判断写法是错误的:
right(Str,10) 是取Str最右边的10个字符,而不是取第10个。当然不是"/"
可以这样判断
if Instr(Right(Str,10),"/")=0 then
else
end if

if right(file1.path,10)<>"/"then 应该是
if right(file1.path,1)<>"/"then
这是判断file1.path的最后一个字符是否是“\”,如果不是,则file1.path +"\"+ 文件名,如果是 ,则file1.path+ 文件名

楼主,加强学习哦