If I dont know the hole path og the file, but knows that it is in the same directory as the program, how do I refer to it, because I can't just say:
Open "File.txt" For Random As #1
as would be natural.
-Nack
Printable View
If I dont know the hole path og the file, but knows that it is in the same directory as the program, how do I refer to it, because I can't just say:
Open "File.txt" For Random As #1
as would be natural.
-Nack
app.path will return your program's location.
open app.path & "\file.txt"
Thanks!
Usually you wont run into this problem but you should test for it anyway.
App.path returns a slash at the end when you are in the Root directory (ex: C:\) but it does not if you are not in the root (ex: C:\temp)
Therefore you should always use this code to make sure its done properly. Add it to a module or the form code.
VB Code:
public function getFilePath(strPath as String, strFileName as String) as String if Right(strPath, 1) <> "\" then getFilePath = strPath & "\" & strFileName else getFilePath = strPath & strFileName end if end Function
Then call it like this
VB Code:
Dim strFilePath as String strFilePath = GetFilePath(app.path, "myfilename.txt") open strFilePath for input as #1 'or whatever u want to do with it 'etc etc