5 Replies - 4109 Views - Last Post: 04 November 2011 - 01:04 PM Rate Topic: -----

#1 ryan.hunt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-November 11

Creating an array for multiple choice questions

Posted 03 November 2011 - 08:53 AM

Hi, im new to the forums and am wondering if anyone can help me out. Im in the process of creating an array for a set of multiple choice questions but i am having a few problems. Im an absolute beginner at VB and i am creating a quiz that users will select one of three possible questions and then depending on their answer a +1 value will be added to the score. However I do not know where my questions and answerrs are supposed to go, from what i have read online i have to use (0, 1) format to give possible answers but i do not know how i would make the questions and aswers display in textboxes on my form. At the bottom of my code i have also included code to randomise the questions although im unsure as to if it is correct. At the moment i can run my form fine without any problems but my main issue is to how i will get the questions and answers linked to my textboxes on my form. I apologise if i am being at all vague i would be happy to clarify anything. Thanks for any help guys.


 Public Class frmTest
   
Private ran As Random = New Random()
    Public intScore As Integer
    Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click


        'Turns the message box invisible when start is clicked
        lblMessage.Visible = False

        'turns the start button invisible when clicked
        cmdStart.Visible = False

        'makes the groupbox for the questions and answers visible when start is clicked
        gbQandA.Visible = True


        Dim PowerpointQuiz(20, 2) As String

        PowerpointQuiz(0, 0) = "Title only"
        PowerpointQuiz(0, 1) = "Title and Content"
        PowerpointQuiz(0, 2) = "Title and Text"



        Dim strResult As String = String.Empty
        Dim rndQuestion As String
        rndQuestion = ran.Next(0, 29)

        PowerpointQuiz(0, 0) = "To add a new slide that may have text or graphics or both, which slide layout should you choose?"




    End Sub 

This post has been edited by smohd: 03 November 2011 - 08:57 AM
Reason for edit:: code tags fixed


Is This A Good Question/Topic? 0
  • +

Replies To: Creating an array for multiple choice questions

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Creating an array for multiple choice questions

Posted 03 November 2011 - 09:20 AM

This is a common problem. It comes from trying to build a program from scratch before learning how your chosen coding language works, or the concepts behind programming for Windows.

Basically, you can't expect to learn how to code by sitting down and building a program from scratch. That would be like saying "I'm going to learn engineer by sitting down and building a car." You have to learn the basics, learn the concepts, learn the language... before you can start designing.


Quote

I have a little coding experience but I need to write ...


You need to start there. I can't say "I have little experience in speaking Russian, but I have been assigned to write a mystery novel in Russian. Can you help me?"

We can help you by saying "First learn basic programming and the language of C#. Then take on assignments." Could someone here write this program for you? Sure. Could someone here map out all the processes you need to follow and do the Software Design part of this in the slim hope you could code it from there? Sure. But we don't volunteer to do the job that you're either getting paid for, or getting a grade for. You may want to read this.

For now, just work on the lessons. Do a self-teaching book from cover to cover. Then consider writing a program.

Don't try to create a useful working program to fit a need of yours (or a for-pay contract) as your introduction to coding project. When you are learning to code you don't know enough to code a program, let alone know how to engineer the architecture of a program. It would be like saying "I don't know how to read sheet music, or play an instrument. I think I'll write a 3 act opera as my first learning experience."

I don't say this to be mean. We've seen lots of new coders take this approach and we know it doesn't work. Trying to design your own programs before you understand the basics of the code language you've chosen just leads to problems, frustrations, and 'swiss-cheese' education (lots of holes).


Resources, references and suggestions for new programmers. - Updated Oct 2011
Spoiler

This post has been edited by tlhIn`toq: 03 November 2011 - 09:20 AM

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Creating an array for multiple choice questions

Posted 03 November 2011 - 09:26 AM

Whatever learning resource you are currently using... You want to re-read the area about arrays.

Notice in your code lines 20 and 30. You assign two different text values to the same element of the array.


20       PowerpointQuiz(0, 0) = "Title only"

30       PowerpointQuiz(0, 0) = "To add a new slide that may have text or graphics or both, which slide layout should you choose?"



The question is going to overwrite the first possible answer.
Was This Post Helpful? 1
  • +
  • -

#4 ryan.hunt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-November 11

Re: Creating an array for multiple choice questions

Posted 03 November 2011 - 09:48 AM

Cheers for the reply! I know im kind of jumping into the deep end, its not that i know nothing about VB, i have some knowledge although arrays are completely new to me. Im currently trying to research how to link my array questions and answers to textboxes on my forms at the moment and im having problems trying to find the code, i only just realised i had the same values for the question and answer in the array, thanks for the heads up!
Was This Post Helpful? 0
  • +
  • -

#5 Tryparse  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 80
  • View blog
  • Posts: 193
  • Joined: 20-April 10

Re: Creating an array for multiple choice questions

Posted 03 November 2011 - 09:51 AM

To put text into a textbox, you use the .Text property of the textbox:
TextBox1.Text = PowerpointQuiz(0, 0)

Was This Post Helpful? 0
  • +
  • -

#6 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: Creating an array for multiple choice questions

Posted 04 November 2011 - 01:04 PM

Which brings me to something that is briefly explained for some odd reason in classrooms(at least in 3 classes for me they were), Classes and Objects! You must know these it is crucial to everything that makes Object Oriented Programming.

Classes
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1