CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Location
    United Kingdom
    Posts
    60

    How can I read this text file?

    Hi all,

    I have a text file (.txt) with data in for a game. There is different data on each line a bit like this:

    Level 1
    Data A
    Data B
    Data C

    Level 2
    Data A
    Data B
    Data C

    I have a button (CmdRead) on my form which I want to be able to click and for Data A to go into text box A, Data B into text box B and so on, but only, for a specific level. E.g. all data from level 1 or all data from level 2.

    Any info on how I can do this?? Thanks!

    Mark

  2. #2
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    Code:
    Option Explicit
    
    Sub cmdRead_Click()
        Dim TxStrm          As String
        Dim DesiredLevel    As String
        
        DesiredLevel = MsgBox("Enter Level Number")
        If DesiredLevel = "" Then
            Exit Sub
        End If
        DesiredLevel = "Level " & Trim(DesiredLevel)
        
        Open "C:\Myfile.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, TxStrm
            If DesiredLevel = Trim(TxStrm) Then
                
                Line Input #1, TxStrm
                txBox1.Text = Trim(TxStrm)
                Line Input #1, TxStrm
                txBox2.Text = Trim(TxStrm)
                Line Input #1, TxStrm
                txBox3.Text = Trim(TxStrm)
                
                Exit Do
            End If
        Loop
        Close #1
    End Sub
    Marketing our skills - please participate in the survey and share your insights
    -

  3. #3
    Join Date
    Mar 2002
    Location
    United Kingdom
    Posts
    60
    Code works fine... Thanks.

    Mark

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