请问在VB中用APP.PATH得到当前目录,如果想要的是上一级目录名称应该怎么办???
有个朋友给了如下代码,但是有的时候正常,有的时候反回值不正确。DimParentPathAsStringIfLen(App.Path)<>3ThenParentPath=...
有个朋友给了如下代码,但是有的时候正常,有的时候反回值不正确。
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
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询