CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Inputing files

  1. #1
    Join Date
    Jan 2000
    Posts
    8

    Inputing files

    i am trying to input a txt file into a textbox, how would i do that?


  2. #2
    Join Date
    Dec 1999
    Location
    Malaysia
    Posts
    56

    Re: Inputing files

    i think you can look this up at one of the free books at InformIT library.
    http://www.informit.com/library/
    That should answer some of your questions regarding file i/o.


    ____________________________________
    The VB Bugs in my Life...

  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Inputing files

    There's a really simple method at http://codeguru.developer.com/vb/articles/1764.shtml - here's a summary of the code :


    public Function ReadFile(FileName as string) as string
    '
    Dim i as Integer
    i = FreeFile
    '
    on error GoTo ErrorTrap
    '
    Open FileName for input as #i
    ReadFile = input(LOF(i), i)
    Close #i
    '
    Exit Function
    '
    ErrorTrap:
    '
    ReadFile = ""
    '
    End Function
    '
    public Sub WriteFile(FileName as string, Contents as string)
    '
    Dim i as Integer
    i = FreeFile
    '
    Open FileName for Output as #i
    '
    print #i, Contents
    Close #i
    '
    End Sub




    Using this code you can populate a MultiLine textbox (eg. Text1) with the contents of Config.Sys using :


    Text1.Text = ReadFile("c:\config.sys")




    and write away the contents of Text1 to a file using :


    Call WriteFile("c:\whatever.whatever", Text1.Text)






    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

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