How does App.Path work? Any examples would help, I tried searching but found nothing helpful :(
Printable View
How does App.Path work? Any examples would help, I tried searching but found nothing helpful :(
It returns the path where your project or exe is running at that time.
casey.
Put MsgBox App.Path in a FormLoad sub and see what it gives you.
It comes in handy for getting files. If you stick your file in the same location as your project then you can easily access it.
VB Code:
sFileLocation = App.Path & "\File.txt"
There is one gotcha if you do that.Quote:
Originally Posted by paralinx
VB Code:
If Right$(App.Path, 1) = "\" Then sFileLocation = App.Path & "File.txt" Else sFileLocation = App.Path & "\File.txt" End If
Thats assuming your file isn't on the root of a drive, C: A:Quote:
Originally Posted by paralinx
That way you don't have to think about the / if its needed or not. That way the exe can be anywhere you want it to be. ;)VB Code:
Option Explicit Dim Ap As String Sub Form_Load() If Right$(App.Path, 1) = "\" Then Ap = App.Path Else Ap = App.Path & "\" End If End If Private Sub cmdSave_Click() Open Ap & "Yourfile.txt" For OutPut As #1 'Save data Close #1 End If
Thanks I know what it is now :-)