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

Thread: Strings

  1. #1
    Join Date
    Aug 1999
    Posts
    12

    Strings

    Hey, I'm just wondering how i can make my program read 1 line at a time into a string from either a file or from another text box. Any help would be appreciated. Thanx,
    Thorin



  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Strings

    Well, there are a couple of ways of doing this...
    Using VB 5, you would probably do something like this:

    Sub ReadFile(fn as string)
    dim i as integer
    dim sCurrentLine as string

    i = FreeFile

    Open fn for Output as i
    While Not EOF(#i)
    Line input #i, sCurrentLine
    MsgBox sCurrentLine
    Wend

    Close i
    End Sub




    In VB 6:
    set a reference to the Microsoft Scripting Runtime then paste this code somewhere:

    Sub ReadFile(fn as string)
    dim FSO as Scripting.FileSystemObject
    Dim objReader as Scripting.TextStream

    set FSO = new Scripting.FileSystemObject
    set objReader = FSO.OpenTextFile(fn,ForReading,false)

    While Not objReader.AtEndOfStream
    MsgBox objReader.ReadLine
    Wend
    objReader.Close
    set objReader = nothing
    set FSO = nothing
    End Sub




    Or something like that.

    Hope that helped,
    John


    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

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