Results 1 to 3 of 3

Thread: Reading from a text file

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Reading from a text file

    Can I make my program read from a text file whatever is on a line?Say label1.caption=whatever is on the 1st line, label2.caption=whatever is on the second line and so on?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Do a search of the forums.

    VB Code:
    1. 'use an array of labes:
    2. Dim iLine As Integer, strLine As String
    3.  
    4. Open "C:\FILE.txt" For Input As #1
    5.     While Not EOF(1)
    6.         Input #1, strLine
    7.         lblFileContents(i).Caption = strLine
    8.         iLine = iLine + 1
    9.     Wend
    10. Close #1
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    VB Code:
    1. Dim strLine As String, i%
    2.  
    3.     Open strFile For Input As #1
    4.         Do
    5.            i = i + 1
    6.            If i = 2 Then
    7.                Line Input #1, strLine
    8.                Label1.Caption = strLine
    9.                Exit Do
    10.             End If
    11.         Loop Until EOF(1)
    12.     Close #1
    Roy

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