Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

vb 6 App.Path

Posted on 2003-02-28
5
Medium Priority
?
315 Views
Last Modified: 2010-08-05
hi

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

i do

i got an other folder

c:\test\Magic\Allo.txt

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
thx
Ital
0
Comment
Question by:Ital
5 Comments
 
LVL 14

Accepted Solution

by:
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.


0
 
LVL 28

Expert Comment

by:vinnyd79
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))
Else
    MsgBox App.Path & arrFile(UBound(arrFile))
End If

End Sub
0
 
LVL 4

Expert Comment

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

Expert Comment

by:applayer
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
0
 

Author Comment

by:Ital
ID: 8048132
Exactly what i needed
its perfect
thx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

571 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