• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

opening files

I wrote a program that uses info from a text file. When I tried to copy and run from the A drive it can't find the text file, so I have to change the code a little. What I was wondering, was if there is a way to code it that will work from the C drive or the A drive. Here's the code for the C drive to be able to find the file.

Open App.Path & "\IntTest.txt" For Input As #2

In order for it to work with the A drive I had to change it to this.

Open App.Path & "IntTest.txt" For Input As #2

Well, any ideas??
0
seeshelle
Asked:
seeshelle
1 Solution
 
trilloCommented:
Well your code (the one for the C:\ drive) will only work if the App.Path is not the root.
If you're working on your hard drive's root, App.Path will return C:\ (with the slash) and your could would be just te same as with de floppy drive.

I always use a function to avoid problems:

Public Function GetSlashedPath(sPath As String) As String
    If Len(sPath) = 0 Then
        GetSlashedPath = "\"
    ElseIf Mid(sPath, Len(sPath), 1) = "\" Then
        GetSlashedPath = sPath
    Else
        GetSlashedPath = sPath & "\"
    End If
End Function

This will always return a path with the trailing slash

The you could call
Open GetSlashedPath(App.Path) & "IntTest.txt" For Input As #2
0
 
seeshelleAuthor Commented:
I'll give it a try!! thanks!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now