Click to See Complete Forum and Search --> : include a txt file


Maarten Versteeg
January 13th, 2000, 09:46 AM
Hi,

Is it possible to "include" a txt file, let's say test.txt in my project.
I'm now opening a file for reading with:
Open "C:\project\program\test.txt" for input as #1


But I want to be able to open the file for reading without specifying to whole path, but just specify the filename only.
I'm asking this because my project will be copied several times and every time in a different directory.
Open "C:\project1\program\test.txt" for input as #1


Open "C:\project2\program\test.txt" for input as #1


Open "C:\project3\program\test.txt" for input as #1


When my project becomes very large with multiple files to be opened, I don't want to get errors and change the pathnames everytime for all the files.

Does anyone have I solution how I can handle this problem?

Thanx,
Maarten

Lonely Wolf
January 13th, 2000, 10:18 AM
You can include the txt file in the setup package, so in your app you can use:


global filename as string

'in your sub
filename= app.path +"\"file name"

open filename .....

January 13th, 2000, 08:36 PM
Ok for this code just test it and put it in a command button, just for testing, make 1 textbox named text1, make a commonddialog named commondialog1, and put this in for the command1's click procedure code:
'this lets you pick the txt file
CommonDialog1.Filter = "Text files (*.TXT)|*.TXT"
CommonDialog1.ShowOpen 'display Open dialog box
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Input As #1
On Error GoTo TooBig: 'set error handler
Do Until EOF(1) 'then read lines from file
Line Input #1, LineOfText$
AllText$ = AllText$ & LineOfText$ & Wrap$
Loop
text1.Text = AllText$ 'display file
text1.Enabled = True
mnuItemClose.Enabled = True
mnuItemOpen.Enabled = False 'enable scroll
CleanUp:
Form1.MousePointer = 0 'reset mouse
Close #1 'close file
End If
Exit Sub
TooBig: 'error handler displays message
MsgBox ("The specified file is too large.")
Resume CleanUp: 'then jumps to CleanUp routine
End Sub