|
-
Feb 5th, 2002, 01:46 PM
#1
Thread Starter
Junior Member
Use file without specifying hole path
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
-
Feb 5th, 2002, 01:49 PM
#2
Frenzied Member
app.path will return your program's location.
-
Feb 5th, 2002, 01:49 PM
#3
open app.path & "\file.txt"
-
Feb 5th, 2002, 01:56 PM
#4
Thread Starter
Junior Member
-
Feb 5th, 2002, 01:57 PM
#5
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|