Need your help: read text file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • portCo

    #1

    Need your help: read text file

    Hello there,

    I am creating a vb application which is some like like a questionare.

    Application read a text file which contains many questions and display
    one question and the input is needed from user to calculate the score.

    Here is a problem.

    I can read a text file. However, it's read whole file at a time. So,
    it only displays the last question.

    Is there any way I can read one line from a text file and wait for a
    user input and when user puts an answer and click next then read next
    line and wait for a user input and so on.

    Do you guys have any idea or hint that I can use?


    Any input from you will be appreciated.

    Thank you,

  • portCo

    #2
    Re: Need your help: read text file

    By the way, I am using Visual Basic 2005.

    On Jul 30, 9:12 am, portCo <woos...@gmail. comwrote:
    Hello there,
    >
    I am creating a vb application which is some like like a questionare.
    >
    Application read a text file which contains many questions and display
    one question and the input is needed from user to calculate the score.
    >
    Here is a problem.
    >
    I can read a text file. However, it's read whole file at a time. So,
    it only displays the last question.
    >
    Is there any way I can read one line from a text file and wait for a
    user input and when user puts an answer and click next then read next
    line and wait for a user input and so on.
    >
    Do you guys have any idea or hint that I can use?
    >
    Any input from you will be appreciated.
    >
    Thank you,

    Comment

    • Lloyd Sheen

      #3
      Re: Need your help: read text file


      "portCo" <woosubc@gmail. comwrote in message
      news:1185811931 .337479.103000@ i13g2000prf.goo glegroups.com.. .
      Hello there,
      >
      I am creating a vb application which is some like like a questionare.
      >
      Application read a text file which contains many questions and display
      one question and the input is needed from user to calculate the score.
      >
      Here is a problem.
      >
      I can read a text file. However, it's read whole file at a time. So,
      it only displays the last question.
      >
      Is there any way I can read one line from a text file and wait for a
      user input and when user puts an answer and click next then read next
      line and wait for a user input and so on.
      >
      Do you guys have any idea or hint that I can use?
      >
      >
      Any input from you will be appreciated.
      >
      Thank you,
      >
      Assuming that the file contains one question per line you would do the
      following :

      Read you file as you do now into a string. Then split the string on the
      vbcrlf which should give you an array of strings.

      Then loop thru you array displaying the question, waiting for the answer,
      recording the answer and then going to the next question until the questions
      are complete.

      Hope this helps

      Lloyd Sheen

      Comment

      • portCo

        #4
        Re: Need your help: read text file

        Thank you for your input.

        The file contains like

        1. Is VB stand for Visual Bag?, F
        2. 1. Is VB stand for Visual Basic?, T

        I am confused and not sure about "waiting for the answer". How can I
        wait for the answer before go into next question?

        This is my question.

        Thanks again

        -portco

        On Jul 30, 9:59 am, "Lloyd Sheen" <a...@b.cwrot e:
        "portCo" <woos...@gmail. comwrote in message
        >
        news:1185811931 .337479.103000@ i13g2000prf.goo glegroups.com.. .
        >
        >
        >
        >
        >
        Hello there,
        >
        I am creating a vb application which is some like like a questionare.
        >
        Application read a text file which contains many questions and display
        one question and the input is needed from user to calculate the score.
        >
        Here is a problem.
        >
        I can read a text file. However, it's read whole file at a time. So,
        it only displays the last question.
        >
        Is there any way I can read one line from a text file and wait for a
        user input and when user puts an answer and click next then read next
        line and wait for a user input and so on.
        >
        Do you guys have any idea or hint that I can use?
        >
        Any input from you will be appreciated.
        >
        Thank you,
        >
        Assuming that the file contains one question per line you would do the
        following :
        >
        Read you file as you do now into a string. Then split the string on the
        vbcrlf which should give you an array of strings.
        >
        Then loop thru you array displaying the question, waiting for the answer,
        recording the answer and then going to the next question until the questions
        are complete.
        >
        Hope this helps
        >
        Lloyd Sheen- Hide quoted text -
        >
        - Show quoted text -

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Need your help: read text file

          As you mean with a Text file a txt file, formely also called asci file or
          whatever, than the answer is simple,

          "No'' that is not possible.

          You would have to use a binary file (formaly named a random file) or a
          database.

          However with so much memory today in every computer is the question in my
          eyes a little bit sily and will the solution given by Lloyd be good (and
          fast) enough as that fits you.

          Cor

          "portCo" <woosubc@gmail. comschreef in bericht
          news:1185811931 .337479.103000@ i13g2000prf.goo glegroups.com.. .
          Hello there,
          >
          I am creating a vb application which is some like like a questionare.
          >
          Application read a text file which contains many questions and display
          one question and the input is needed from user to calculate the score.
          >
          Here is a problem.
          >
          I can read a text file. However, it's read whole file at a time. So,
          it only displays the last question.
          >
          Is there any way I can read one line from a text file and wait for a
          user input and when user puts an answer and click next then read next
          line and wait for a user input and so on.
          >
          Do you guys have any idea or hint that I can use?
          >
          >
          Any input from you will be appreciated.
          >
          Thank you,
          >

          Comment

          • Lloyd Sheen

            #6
            Re: Need your help: read text file


            "portCo" <woosubc@gmail. comwrote in message
            news:1185819275 .458447.316010@ i13g2000prf.goo glegroups.com.. .
            Thank you for your input.
            >
            The file contains like
            >
            1. Is VB stand for Visual Bag?, F
            2. 1. Is VB stand for Visual Basic?, T
            >
            I am confused and not sure about "waiting for the answer". How can I
            wait for the answer before go into next question?
            >
            This is my question.
            >
            Thanks again
            >
            -portco
            >
            On Jul 30, 9:59 am, "Lloyd Sheen" <a...@b.cwrot e:
            >"portCo" <woos...@gmail. comwrote in message
            >>
            >news:118581193 1.337479.103000 @i13g2000prf.go oglegroups.com. ..
            >>
            >>
            >>
            >>
            >>
            Hello there,
            >>
            I am creating a vb application which is some like like a questionare.
            >>
            Application read a text file which contains many questions and display
            one question and the input is needed from user to calculate the score.
            >>
            Here is a problem.
            >>
            I can read a text file. However, it's read whole file at a time. So,
            it only displays the last question.
            >>
            Is there any way I can read one line from a text file and wait for a
            user input and when user puts an answer and click next then read next
            line and wait for a user input and so on.
            >>
            Do you guys have any idea or hint that I can use?
            >>
            Any input from you will be appreciated.
            >>
            Thank you,
            >>
            >Assuming that the file contains one question per line you would do the
            >following :
            >>
            >Read you file as you do now into a string. Then split the string on the
            >vbcrlf which should give you an array of strings.
            >>
            >Then loop thru you array displaying the question, waiting for the answer,
            >recording the answer and then going to the next question until the
            >questions
            >are complete.
            >>
            >Hope this helps
            >>
            >Lloyd Sheen- Hide quoted text -
            >>
            >- Show quoted text -
            >
            >
            The loop asking questions would be implied not a "real" loop. What you
            would do is once you have finished reading and parsing (splitting) the file
            you will display a question and wait for an answer. The answer will be the
            event that you then process the answer and see if there are more questions
            to be asked. If so then ask the next (and so on). If the questions are
            complete then you will .... do whatever it is you do with the results.

            Hope this helps.
            Lloyd Sheen

            Comment

            • Phil

              #7
              Re: Need your help: read text file

              Is there any way I can read one line from a text file and wait for a
              user input and when user puts an answer and click next then read next
              line and wait for a user input and so on.
              Dim Question As String
              Dim Answer As String
              FileOpen(1, Filename, OpenMode.Input)
              While Not EOF(1)
              Question = LineInput(1)
              Answer=InputBox (Question)
              End While
              FileClose()



              Comment

              Working...