CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2000
    Location
    Holland
    Posts
    14

    include a txt file

    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


  2. #2
    Join Date
    Nov 1999
    Location
    Italy
    Posts
    80

    Re: include a txt file

    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 .....




    Something over there is coding....
    ... and you don't know!

  3. #3
    Guest

    Re: include a txt file

    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



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured