Need your help: read text file

P

portCo

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,
 
L

Lloyd Sheen

portCo said:
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
 
P

portCo

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
 
C

Cor Ligthert[MVP]

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
 
L

Lloyd Sheen

portCo said:
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

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
 
P

Phil

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top