Results 1 to 3 of 3

Thread: Read strings from txt

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87
    I have a txt file like this:

    1,question,answer
    2,question,answer
    ...

    If I need question 4 (for example) and I want the question in lblQuestion and the answer in lblAnswer, how do I need to do this? I think i need to use line input but I don't know how.

    Can somebody help me please?

  2. #2
    Guest
    Code:
    Dim iCount As Integer
    
    Open "MyFile.txt" For Input As #1
    Do While Not EOF(1)
        'Keep track of the line number
        iCount = iCount + 1
        Line Input #1, tmp
        
        'If the line is 4 then...
        If iCount = 4 Then
            'Get the qestion and answer
            tmp = Split(tmp, ",")
            'Display them in a Label
            lblQuestion = tmp(1)
            lblAnswer = tmp(2)
        End If
    Loop
    Close #1

  3. #3
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    Originally posted by moperke
    I have a txt file like this:

    1,question,answer
    2,question,answer
    ...

    If I need question 4 (for example) and I want the question in lblQuestion and the answer in lblAnswer, how do I need to do this? I think i need to use line input but I don't know how.

    Can somebody help me please?
    The obvious answer would be to use a database, but if you must use comma delimitted text then you should probably use a datatype declared as an array and write an I/O Sub:
    In Declarations

    Public Type MyData
    Num as Integer
    Question as String
    Answer as String
    End Type

    In DataRetrival Routine
    Dim Dat() as MyData
    Determine Number of records
    ReDim Dat(Number of Records + 1)


    Open.....'Open Your Txt File
    For intX1 = 1 to NumberOfRecords + 1
    Read Data Record.....'Depending on data file type and format
    Dat(intX).Num=Num
    Dat(intX).Question=Question
    Dat(intX).Answer=Answer
    Next IntX

    Use Dat(0) For Handling The record that you are editing....

    This is a lot of trouble to avoid using a database.

    Hunter


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