vb 6 App.Path

Posted on 2003-02-28
Medium Priority
Last Modified: 2010-08-05

the path of my program is  : c:\test\funny\

i do

i got an other folder


i need to be able to go get that file

with the App.Path

so basacly, what i need is the command to go back one shot. like a CD..

1- be able to go one folder back
Question by:Ital
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Accepted Solution

Esopo earned 100 total points
ID: 8045489
Use the following code to retreive the upper directory:

Dim TheFile as String
Dim J as Integer

For J=len(App.Path) To 1 step -1
If mid(App.Path, J, 1) = "\" then Exit For
next J

TheFile=Left(App.Path, J)

'TheFile' contains "c:\test\", now just add "Magic\Allo.txt
", I recommend you do a couple tests before feeling comfortable with this code.

Best regards.

LVL 28

Expert Comment

ID: 8045587
you could use split to get the filename:

Private Sub Command1_Click()
Dim arrFile() As String
arrFile = Split("c:\test\Magic\Allo.txt", "\")
If Left(App.Path, 1) <> "\" Then
    MsgBox App.Path & "\" & arrFile(UBound(arrFile))
    MsgBox App.Path & arrFile(UBound(arrFile))
End If

End Sub

Expert Comment

ID: 8046250
   Dim MyDataFile As String
    MyDataFile = StrReverse(App.Path)
    MyDataFile = StrReverse(Right(MyDataFile, Len(MyDataFile) - InStr(1, MyDataFile, "\"))) & "\Magic\Allo.txt"

Expert Comment

ID: 8046716
'strFolder will contain the path to the folder you want

Dim strFolder As String
Dim x As Integer '
For x = Len(App.Path) To 1 Step -1
  If Mid(App.Path, x, 1) = "\" Then
    strFolder = Mid(App.Path, 1, Len(App.Path) - (x + 1))
  End If
Next x

Author Comment

ID: 8048132
Exactly what i needed
its perfect

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question