Results 1 to 8 of 8

Thread: VB 2010 - Program for multiple choice test

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    6

    Unhappy VB 2010 - Program for multiple choice test

    Hi,

    I'm really new at programming and was looking for guidance about a project I have.

    I have to design a program that administers a multiple choice test to users. It delivers questions one at a time, from a predefined test file for the user to answer. It also marks and displays a score at the end of the test.

    First, a QUESTION form verify's the user's registration status and access. The user provides a registration number and password and the program reads it from a "registration.txt" file to determine if the user is eligible to take the test (i.e., they are registered to take it). If it is correct, then the user presses the "Begin" button. If not, then a message appears and the student tries again to enter the information.

    A read only text box will display the score at the end of the test (String with format correct/total) and the user can't retake the test.

    Second, a QUESTION form opens after clicking "Begin" on the entry form. The questions are going to be from a "testfile.txt" file.
    Each question is on multiple lines in the file. The first line consists of the question followed by possible answers followed by the correct answer ( 3 items are separated by "#"). The current question number and the question will be displayed in textboxes.
    'n'= possible answers; so each of the next 'n' lines provides a possible answer. All possible answers will be displayed in a Listbox.
    After the user selects an answer, an ''Enter'' button is pressed. This will submit and evaluate the answer. If nothing is selected a textbox should appear and display the error message (APPEARS ONLY IF THERE IS AN ERROR). After pressing ''Enter'', the next question is displayed.
    When all questions answered, the entry form is displayed again and displays the score.

    I know that's a lot of information, but I wanted it to be really clear.
    Would it be best to cycle/loop the questions with a DoWhile loop? And how would I store the answers while the user goes through the test?

    I feel a little over my head...

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: VB 2010 - Program for multiple choice test

    You have to take this one step at a time. Don't just post your whole assignment and expect anything to get done.

    The assignment is broken up into small and easy parts. That's how all projects get done. Breaking everything up into smaller, more manageable parts makes your life easier. And the assignment did it for you!

    So pick where you'd like to begin and go from there. Try to code what you've chosen and when you have problems figuring that out, come back and show us what you tried, what's happening and what you're expecting to happen.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    6

    Re: VB 2010 - Program for multiple choice test

    Hi,

    Thanks, I was just looking to see if someone could tell me a good place to start. Okay, so I'm trying to figure out how to add the answers into the listbox. Here's what's in my TestFile.txt:

    Question 1. What is the capital of Canada?#3#1
    Ottawa
    Toronto
    Vancouver
    Question 2. What is the colour of the sky?#3#2
    Brown
    Blue
    Green
    Question 3. Who directed "Titanic" (1997)?#3#1
    James Cameron
    Martin Scorsese
    Steven Spielberg
    Question 4. What cells are present in the adaptive immune response?#3#3
    Neutrophils
    Erythrocytes
    Helper T-cells
    Question 5. What is the heartbeat of a neonate?#3#2
    60-80 beats/min
    110-160 beats/min
    145-185 beats/min

    So I want to add just the answers to the listbox but all i can figure out is:

    Dim fileTest As IO.StreamReader = IO.File.OpenText("testfile.txt")
    Dim line As String
    Do While Not fileTest.EndOfStream
    lstAnswers.Items.Add(fileTest.ReadLine())
    Loop
    fileTest.Close()

    but that just adds it all into the textbox. How do i add just the answers?

  4. #4
    Hyperactive Member
    Join Date
    Oct 2010
    Location
    Indiana
    Posts
    457

    Re: VB 2010 - Program for multiple choice test

    I'd get rid of the Txt file, and put it into a database file, much easier to work with (For your intended purpose), and you can password protect it.

    In VS 2010 the wizards and drag and drop features for databases makes it pretty easy to setup. For more info on working with databases, lookup ado.net. There are several good forums on this site, and microsoft's msdn site.
    Last edited by nO_OnE; Apr 5th, 2011 at 12:54 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    6

    Re: VB 2010 - Program for multiple choice test

    Actually, we haven't covered databases in my class so we're not allowed to use it for this particular program. Is there a way to do with the text files?

  6. #6
    Hyperactive Member
    Join Date
    Oct 2010
    Location
    Indiana
    Posts
    457

    Re: VB 2010 - Program for multiple choice test

    Well, you can create an array (right now you just have a single string, convert the line string to an array. There's also more info on arrays if you search for them...), and just copy the lines from the text file into the array line by line as you advance the array's index, then fill the text boxes from the array. I would also put the answer on a separate line.

    If you do it in an array then it would be in multiples of 4 (from the way your text file is setup). so the question would be index 0, then the choices would be index's 1-3, then the next quesition would be index 4, and it's choices would be index's 5-7, etc...
    Last edited by nO_OnE; Apr 5th, 2011 at 01:23 AM.

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    6

    Re: VB 2010 - Program for multiple choice test

    Okay, I created the array:

    Dim lines() As String = System.IO.File.ReadAllLines("testfile.txt")

    the question would be:

    TextBox1.Text = lines(0)

    and so the listbox answers would be:

    lstAnswers.Items.Add(" ")
    lstAnswers.Items.Add(lines(1))
    lstAnswers.Items.Add(lines(2))
    lstAnswers.Items.Add(lines(3))

    but how do I get the program to loop the questions? and how would I save the answer that the user selects so that I can compute the score at the end?

  8. #8
    Hyperactive Member
    Join Date
    Oct 2010
    Location
    Indiana
    Posts
    457

    Re: VB 2010 - Program for multiple choice test

    Quote Originally Posted by 00brandnew View Post
    but how do I get the program to loop the questions?
    There are many of different ways. You should have already looped through the questions from the text file, so you don't need to loop through them again, you simply change the index of the array to get to the questions you want. One of the simplest would be to set a Public Variable so that when the user first starts the test it the variable is 0, then add 4 to it every time they navigate to the next question. (You use the variable to reference the Array instead of the numeric values).
    Like:
    Code:
    Public X as string
    
    
    Formload event
     X=0
    
    Textbox1.Text = lines(x)
    
    Dim x1 as string
          X1 = x+1
    Dim x2 as string
          X2 = X+2
    lstAnswers.Items.Add(lines(x1))
    lstAnswers.Items.Add(lines(x2))
    etc...
    
    
    
    
    
    For the "Next Question" Event
         X = X+4
    
    Dim x1 as string
          X1 = x+1
    Dim x2 as string
          X2 = X+2
    lstAnswers.Items.Add(lines(x1))
    lstAnswers.Items.Add(lines(x2))
    etc...
    There's more code you will have to add (such as figuring out if your on the last question). Hopefully this gives you a place to start...

    Quote Originally Posted by 00brandnew View Post
    how would I save the answer that the user selects so that I can compute the score at the end?

    we haven't covered databases in my class so we're not allowed to use it for this particular program. Is there a way to do with the text files?
    Again, there is a multitude of ways, but it depends on how you are trying to accomplish it, and what you can use.

    I would assume you want to store the info for later retrieval. The simplest thing would be to can wright it to a text file, and have it so when they sign in it stores their name, and date first (That way it makes it easier to search), then stores the answer with some sort of a flag, like a yes or no if they got it wrong or right.

    You might want to look up XML and using "Tags," it makes it easier to search through txt files...
    Last edited by nO_OnE; Apr 6th, 2011 at 09:16 PM.

Tags for this Thread

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