• 0

[VB 6] Reading a text file line by line.


Question

Ok, my instructor of my IT class wants me to make a program to make up A+ related tests. He has a few people making their own, and then they will give them to me and I will put them in a program that will make one test of however many questions I tell it to use. Each test is layed out as follows.

Question

choice a (correct)

choice b

choice c

choice d

SPACE

Question

choice a (correct)

choice b

choice c

choice d

And so on. The question and selections don't wrap and are each on one line. My question is, how can I make VB go through and only read questions to add them to an array, and then go through and add the 4 choices for that question to that array?

Edited by c0rrupt
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

If the structure of the file is consistent, then you can probably achieve it fairly easily.

You can probably make a structure called Question, and inside that structure have some string fields which hold the questions and a field which holds the answers...

Then you can make a loop that reads from the beginning of the line of the file to the end, and inside the loop you'd read "Question", don't store that obviously, and then the next line would be the first answer option, so you read that line in and store it in the structure's field for the first option, and then do it for the next choice and yeah... here's a simple idea of how it would work, i don't program in VB6 anymore so i kind of forgot how to read in files.

While(notendoffile)

//Skip the "Question" word

BufferStream.readline

structure.choiceA = BufferStream.readline

structure.choiceB = BufferStream.readline

structure.choiceC = BufferStream.readline

structure.choiceD = BufferStream.readline

End While

yeah that's a general algorithm for it.

Hope this helps, then you can store all these Question structures inside an Array and yeah :)

Link to comment
Share on other sites

  • 0

Well, that is written in .Net (or .Net-ish psuedo code?), he is asking for VB6 code. But as you mentioned, you need to assure the input data is consitent. Force people to enter the information via a web interface to assure the file is correct format. Then, search for examples online to input text files line by line. It is a fairly simple and common task and there are tons of examples on the web. I don't have the time to do this for you.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.