卢沟桥哪个朝代的:请问在VB中用APP.PATH得到当前目录,如果想要的是上一级目录名称应该怎么办???

来源:百度文库 编辑:中科新闻网 时间:2024/05/05 10:42:51
有个朋友给了如下代码,但是有的时候正常,有的时候反回值不正确。
Dim ParentPath As String
If Len(App.Path) <> 3 Then
ParentPath = Mid(App.Path, 1, Len(App.Path) - InStr(App.Path, "\") - 2)
MsgBox "程序所在目录的上级目录是" & ParentPath
Else
MsgBox "程序位于分区根目录" & App.Path
End If

Dim ParentPath As String
Dim s As String

Dim i As Integer

Do Until s = "\"

s = Mid(App.Path, Len(App.Path) - i, 1)
i = i + 1
Loop

If Len(App.Path) <> 3 Then
ParentPath = Mid(App.Path, 1, Len(App.Path) - i)

MsgBox "程序所在目录的上级目录是" & ParentPath
Else
MsgBox "程序位于分区根目录" & App.Path
End If

本地test了一下,不知道你说的是哪里返回不对。
ParentPath比app.path少了一级目录而已