7 Replies - 934 Views - Last Post: 12 May 2011 - 05:27 PM Rate Topic: -----

#1 karenhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 24-January 11

Using an array to print out test results based on background color.

Posted 12 May 2011 - 06:44 AM

I've created a program that requires students to answer addition questions.
I have the code so that it calculates if the answer is correct, along with outputing the correct answer into a textbox.
If the answer is correct the textbox background colour changes to green.
If the answer is inocrrect the textbox background colour changes to red.

I've done this using an array, and I want to use this array to calculate how many questions the students have answered correctly, and output them onto another page.

I'm not sure is something like this would work:
I was thinking about giving the textbox that outputs the grade score a value of 10. For every red box that is highlighted, 1 is taken away from the texbox value, outputting the amount of questions the user has answered correctly.

Here is my array so far, not including the ability to output how many answers the student has answered correctly.
Can someone help me doing this please?

    Public Num1(10), Num2(10) As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim array() As TextBox = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6}
        Dim i As Integer = 0




        For i = 0 To 2

            If array(i).Text = array(i + 3).Text Then
                array(i + 0).BackColor = Color.Green





            Else

                array(i + 0).BackColor = Color.Red




            End If
        Next


Is This A Good Question/Topic? 0
  • +

Replies To: Using an array to print out test results based on background color.

#2 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Using an array to print out test results based on background color.

Posted 12 May 2011 - 07:18 AM

The simplest way would just to be making a counter that increments whenever an correct answer is given, and resets whenever the "game" resets, that should be as simple as adding either a Public or Friend integer variable, and incrementing it every time your logic that determines a right answer happens.

If you want to give more specific details, then you'll likely need to record the answers given, the easiest way being in an 2D array, storing the answers given in the first row and the correct answer in the second row, which can then be used for any summary page information.

I would still need a bit more information to give any code that would be useful for you, more of your source code, or a more detailed explanation of what you want to do in lieu of that.
Was This Post Helpful? 1
  • +
  • -

#3 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 83
  • View blog
  • Posts: 364
  • Joined: 12-January 11

Re: Using an array to print out test results based on background color.

Posted 12 May 2011 - 08:43 AM

I agree with Tarkenfire, I would just add a variable to store the number of correct answers within the loop that changes the color. I have included a change to the code below.

Dim correct as Integer 'you would want this in the class variables
Dim array() As TextBox = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6}  

For i as integer=0 to yourNum
    If array(i).Text = array(i + 3).Text Then 
        array(i + 0).BackColor = Color.Green
        correct+=1
    Else 
        array(i + 0).BackColor = Color.Red  
    End If 
Next


Was This Post Helpful? 1
  • +
  • -

#4 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Using an array to print out test results based on background color.

Posted 12 May 2011 - 09:19 AM

The thing I worry about with adding the counter there is that b/c it's inside of a loop, it might get incremented more than once per right answer.
Was This Post Helpful? 0
  • +
  • -

#5 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 83
  • View blog
  • Posts: 364
  • Joined: 12-January 11

Re: Using an array to print out test results based on background color.

Posted 12 May 2011 - 09:28 AM

View PostTarkenfire, on 12 May 2011 - 09:19 AM, said:

The thing I worry about with adding the counter there is that b/c it's inside of a loop, it might get incremented more than once per right answer.


I'm not sure I follow you on that one. You might have to run me through it. If "i" is the loop counter, "correct" gets incremented on only answers which are defined as correct, and i properly increments for each loop (which is taken care of by the "for"), how can the counter get incremented more than once per correct answer? If this were a more complicated loop I could see confusion arising as to where the counter gets incremented, but in a sample such as this, there really isn't much room for confusing loop structures. Maybe I'm just not understanding your meaning though.
Was This Post Helpful? 0
  • +
  • -

#6 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Using an array to print out test results based on background color.

Posted 12 May 2011 - 09:57 AM

View PostPsyguy, on 12 May 2011 - 09:28 AM, said:

View PostTarkenfire, on 12 May 2011 - 09:19 AM, said:

The thing I worry about with adding the counter there is that b/c it's inside of a loop, it might get incremented more than once per right answer.


I'm not sure I follow you on that one. You might have to run me through it. If "i" is the loop counter, "correct" gets incremented on only answers which are defined as correct, and i properly increments for each loop (which is taken care of by the "for"), how can the counter get incremented more than once per correct answer? If this were a more complicated loop I could see confusion arising as to where the counter gets incremented, but in a sample such as this, there really isn't much room for confusing loop structures. Maybe I'm just not understanding your meaning though.


That's making the assumption that the loop in the program is only run once per program run, to check all questions, without seeing more source code, it's equally as likely that that loop might be run once per question, meaning the full loop might be run though 10 times instead of once.
Was This Post Helpful? 0
  • +
  • -

#7 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 83
  • View blog
  • Posts: 364
  • Joined: 12-January 11

Re: Using an array to print out test results based on background color.

Posted 12 May 2011 - 10:04 AM

Ok, I see what you are saying. True enough. I guess more information is needed to ensure that it will give the intended result.
Was This Post Helpful? 0
  • +
  • -

#8 karenhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 24-January 11

Re: Using an array to print out test results based on background color.

Posted 12 May 2011 - 05:27 PM

Thanks for the help it's been resolved. The +=1 idea did work, and the program is nearly finished and working well thanks. My first idea did over complicate everything.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1