Reading files in Visual Basic, GW-Basic style

April 6, 2004 on 3:26 pm | In General |

Recently, someone asked me how to quickly read a file with Visual Basic code without dealing with streams.

Of course, once you learn doing this in GW-Basic, Basica, and friends, it sticks in your mind. Those who forgot, shame on you!

    Dim iFileNumber As Integer
    Dim sLine As String

    iFileNumber = FreeFile
    Open "C:stats.log" For Input As iFileNumber
    Do While Not EOF(iFileNumber)
        Input #iFileNumber, sLine
        MsgBox sLine
    Loop

Related Posts:

2 Comments »

RSS feed for comments on this post.

  1. If you are wanting to read a whole line (up to the next cr/lf pair), ammend your code to:

    Line Input #iFileNumber, sLine

    Input by itself is used to read comma seperated values in the order they were written:

    Print #iFileNumber, 1, “A test”

    Input #iFileNumber, iMyInt, sMyString

    Hope this helps :-)

    Comment by Richard@Home — 8 April 2004 #

  2. Of course! :-)

    Comment by Eddy Young — 8 April 2004 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>





Powered by blog.mu with Pool theme design by Borja Fernandez.