Problem with starting code

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 2036 Views - Last Post: 03 July 2013 - 08:05 PM Rate Topic: -----

#1 khris123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 13

Problem with starting code

Posted 03 July 2013 - 08:22 AM

Hello this is what I have to create :Create a project in which the user will complete a 10-question survey. Create a form containing labels with each of the questions and a group of radio buttons for each question with the following responses: Always. Usually. Sometimes. Seldom. and 'ever.
Use a two dimensional array to accumulate the number of each response for each question.
Have a menu or button option that will print an item analysis on the
printer that shows the question number and the count for each response.

I know I have to have a two dimensional array already but im not really sure how, ex.
i have to have 10 questions I don't want to have a crazy looking program with 10 labels and 50 buttons, how do i make that simpler, and how do i move on from one question to the next, I had no problem with coding before this, im just plain old stuck

Just thought of having 10 labels and run maybe an if then statement and a .show for each label when its their turn would that be the easiest route ?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with starting code

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15066
  • View blog
  • Posts: 60,160
  • Joined: 12-June 08

Re: Problem with starting code

Posted 03 July 2013 - 08:24 AM

Why not have your ten questions/radio button groups in a straight list, or do they need to be only one viewable question at a time?
Was This Post Helpful? 0
  • +
  • -

#3 khris123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 13

Re: Problem with starting code

Posted 03 July 2013 - 08:28 AM

Thats what i was afraid of having, 10 questions with 50 different radio buttons it just seems like a too much code, was hoping for a simplified way
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15066
  • View blog
  • Posts: 60,160
  • Joined: 12-June 08

Re: Problem with starting code

Posted 03 July 2013 - 08:32 AM

Well.. depending on how you store your data you can have _a_ form, with a label, radio buttons, a 'next question', and 'back a question'... So say you store your questions in an array of strings... ten questions, ten array items. You'll need an integer to track which question (array index) you are on.

The survey starts up, pushes the first question into the label, and waits for the user's response.

The user clicks a response and then 'next'. The app saves the response in 2d array, increments the counter, and pulls the next question from the string array. Repeat until the counter is maxed out for questions.
Was This Post Helpful? 0
  • +
  • -

#5 khris123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 13

Re: Problem with starting code

Posted 03 July 2013 - 08:57 AM

okay this is my code so far but for some reason it says that questionbox(x).QuestionString is not a string
Option Explicit On
Option Strict On
Public Class SurveyForm


    Structure Question
        Dim QuestionString As String

    End Structure
    Private QuestionGroup(9) As String
    Private Sub QuestionGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuestionGroupBox.Enter

    End Sub

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()

    End Sub

    Private Sub SurveyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        QuestionGroup(0).QuestionString = "Question 1: Do you read the textbook chapter after class"
        QuestionGroup(1).QuestionString = "Question 2: Do you complete the homework when it is assigned"
        QuestionGroup(2).QuestionString = "Question 3: Do attend class regularly"
        QuestionGroup(3).QuestionString = "Question 4: Do you participate in class discussions"
        QuestionGroup(4).QuestionString = "Question 5: Do you participate in a study group"
        QuestionGroup(5).QuestionString = "Question 6: Do you answer questions in the textbook"
        QuestionGroup(6).QuestionString = "Question 7: Do you practice with the hands on excersice"
        QuestionGroup(7).QuestionString = "Question 8: Do you try little projects to test all new topics"
        QuestionGroup(8).QuestionString = "Question 9: Do you ask questions when you are unsure about a topic?"
        QuestionGroup(9).QuestionString = "Question 10: Do you use the online help to learn more about each feature?"
    End Sub
End Class



I fixed the code i had my group as string when i should have put it as question

okay next question is how do i get the questions to show in order? and how do i count the radio buttons

This post has been edited by modi123_1: 03 July 2013 - 09:00 AM
Reason for edit:: fixed botched code tag

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15066
  • View blog
  • Posts: 60,160
  • Joined: 12-June 08

Re: Problem with starting code

Posted 03 July 2013 - 09:02 AM

Quote

okay next question is how do i get the questions to show in order?

Have a global integer that you tracks which question index you are on. Each time a user clicks 'next' it increments.

Quote

and how do i count the radio buttons

I am not sure if I follow. Look - for a given set of radio buttons you can just give them a simple numbering scheme..

Always. = 0
Usually. = 1
Sometimes. = 2
Seldom. = 3
never. =4
Was This Post Helpful? 0
  • +
  • -

#7 khris123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 13

Re: Problem with starting code

Posted 03 July 2013 - 09:07 AM

I am somehow supposed to be able to print something like this

what do you mean by global integer so far i have this it shows the 1st question and thats about it
Dim indexinteger As Integer = 0
        QuestionLabel.Text = QuestionGroup(indexinteger).QuestionString

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15066
  • View blog
  • Posts: 60,160
  • Joined: 12-June 08

Re: Problem with starting code

Posted 03 July 2013 - 09:14 AM

Quote

I am somehow supposed to be able to print something like this

Okay.. so a grid, text area, multiline label, etc can accomplish that.

Quote

what do you mean by global integer so far i have this it shows the 1st question and thats about it

A variable.. that is an integer.. that is in global scope (ie - not declared in a method).
Was This Post Helpful? 0
  • +
  • -

#9 khris123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 13

Re: Problem with starting code

Posted 03 July 2013 - 09:18 AM

im a noob at code so im not sure how you write any of those, should i do like a if button is clicked indexinteger +1 type thing? and im clueless on the grid
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15066
  • View blog
  • Posts: 60,160
  • Joined: 12-June 08

Re: Problem with starting code

Posted 03 July 2013 - 09:24 AM

Quote

im a noob at code so im not sure how you write any of those

I have no idea what "those" is supposed to reference.

Quote

should i do like a if button is clicked indexinteger +1 type thing?

That is what I have been saying.

Quote

and im clueless on the grid

Time to experiment and learn then.

Scope - read about it here.

Example here:
Public Class Form1
    Private lIndex As Int32 = 0 '-- global scope... it is up at the class level.
    Private arrayString() As String = New String() {"abc", "cd"}

    Public Sub SomeMethod()
        '-- if I were to declare it in here the variable would only have scope inside this method.
        Dim lFoo As Int32 = 0
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        '-- notice how I cannot reference lFoo in this method because lFoo does not have scope here.

        If lIndex < arrayString.Length Then
            lIndex += 1 '-- increments lIndex by one
        Else
            lIndex = 0
        End If

        Debug.WriteLine(arrayString(lIndex)) '-- using an integer variable to referecne an index in an array.
    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#11 khris123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 13

Re: Problem with starting code

Posted 03 July 2013 - 09:37 AM

okay i have been trying this +1 but im pretty sure im not coding it right every time i try to create a method it has an error i know it must be something along the line of indexinteger + 1 but am i doing an if else, try, catch, for. nothing seems to be working
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15066
  • View blog
  • Posts: 60,160
  • Joined: 12-June 08

Re: Problem with starting code

Posted 03 July 2013 - 09:39 AM

... care to show what you are doing?
Was This Post Helpful? 0
  • +
  • -

#13 khris123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 13

Re: Problem with starting code

Posted 03 July 2013 - 09:40 AM

i keep getting this error saying it can not be used for 1d arrays here is my code
Option Explicit On
Option Strict On
Public Class SurveyForm


    Structure Question
        Dim QuestionString As String

    End Structure
    Private QuestionGroup(9) As Question
    Private Sub QuestionGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuestionGroupBox.Enter

    End Sub

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()

    End Sub

    Private Sub SurveyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        QuestionGroup(0).QuestionString = "Question 1: Do you read the textbook chapter after class"
        QuestionGroup(1).QuestionString = "Question 2: Do you complete the homework when it is assigned"
        QuestionGroup(2).QuestionString = "Question 3: Do attend class regularly"
        QuestionGroup(3).QuestionString = "Question 4: Do you participate in class discussions"
        QuestionGroup(4).QuestionString = "Question 5: Do you participate in a study group"
        QuestionGroup(5).QuestionString = "Question 6: Do you answer questions in the textbook"
        QuestionGroup(6).QuestionString = "Question 7: Do you practice with the hands on excersice"
        QuestionGroup(7).QuestionString = "Question 8: Do you try little projects to test all new topics"
        QuestionGroup(8).QuestionString = "Question 9: Do you ask questions when you are unsure about a topic?"
        QuestionGroup(9).QuestionString = "Question 10: Do you use the online help to learn more about each feature?"
    End Sub

    Private Sub BeginSurveyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeginSurveyButton.Click
        Dim indexinteger As Integer = 0
        QuestionLabel.Text = QuestionGroup(indexinteger).QuestionString

        If QuestionGroup < QuestionString.Length Then
            QuestionGroup += 1
        End If

        If AlwaysRadioButton.Checked = False Then
        ElseIf NeverRadioButton.Checked = False Then
        ElseIf SeldomRadioButton.Checked = False Then
        ElseIf SometimesRadioButton.Checked = False Then
        ElseIf UsuallyRadioButton.Checked = False Then
            MessageBox.Show("Please select an answer", "Invalid Answer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        End If


    End Sub

    Private Sub AlwaysRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlwaysRadioButton.CheckedChanged, NeverRadioButton.CheckedChanged, SeldomRadioButton.CheckedChanged, SometimesRadioButton.CheckedChanged, UsuallyRadioButton.CheckedChanged
       
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15066
  • View blog
  • Posts: 60,160
  • Joined: 12-June 08

Re: Problem with starting code

Posted 03 July 2013 - 09:48 AM

Any reason you are using a structure here?
06	    Structure Question
07	        Dim QuestionString As String
08	 
09	    End Structure
10	    Private QuestionGroup(9) As Question




34	        Dim indexinteger As Integer = 0


So, that's not at class scope, right? when that method ( Private Sub BeginSurveyButton_Click) is done running that variable disappears. What I was trying to push you towards is bumping that out of method scope and using it globallly.. so even when the method is done the value and the variable are retained... so you know what index you are on.




37	        If QuestionGroup < QuestionString.Length Then
38	            QuestionGroup += 1
39	        End If


What exactly are you doing here? You are asking if a collection object (QuestionGroup) is less than the length of some structure's internal variable "QuestionString"'s length. Does that even remotely make sense?

Then you want to increment a collection object (QuestionGroup)?

Neither of those are right.

What you would be looking do is check if the global variable indexinteger s less than the collection object (QuestionGroup)'s count... if it is then increment global variable indexinteger.
Was This Post Helpful? 0
  • +
  • -

#15 khris123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 13

Re: Problem with starting code

Posted 03 July 2013 - 10:09 AM

okay thanks I fixed the issue it now counts as it should but once i click it after question 10 i get this error saying that it was outside the bounds of the array here is the new code

Option Explicit On
Option Strict On
Public Class SurveyForm


    Structure Question
        Dim QuestionString As String
        Dim AnswerInteger As Integer


    End Structure
    Private QuestionGroup(9) As Question
    Private AnswerGroup(9, 4) As Answer
    Private indexinteger As Integer = 0

    Private Sub QuestionGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuestionGroupBox.Enter

    End Sub

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()

    End Sub

    Private Sub SurveyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        QuestionGroup(0).QuestionString = "Question 1: Do you read the textbook chapter after class"
        QuestionGroup(1).QuestionString = "Question 2: Do you complete the homework when it is assigned"
        QuestionGroup(2).QuestionString = "Question 3: Do attend class regularly"
        QuestionGroup(3).QuestionString = "Question 4: Do you participate in class discussions"
        QuestionGroup(4).QuestionString = "Question 5: Do you participate in a study group"
        QuestionGroup(5).QuestionString = "Question 6: Do you answer questions in the textbook"
        QuestionGroup(6).QuestionString = "Question 7: Do you practice with the hands on excersice"
        QuestionGroup(7).QuestionString = "Question 8: Do you try little projects to test all new topics"
        QuestionGroup(8).QuestionString = "Question 9: Do you ask questions when you are unsure about a topic?"
        QuestionGroup(9).QuestionString = "Question 10: Do you use the online help to learn more about each feature?"
    End Sub

    Private Sub BeginSurveyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeginSurveyButton.Click


        QuestionLabel.Text = QuestionGroup(indexinteger).QuestionString
        If indexinteger < QuestionGroup.Length Then
            indexinteger += 1
        ElseIf indexinteger > QuestionGroup.Length Then
            QuestionLabel.Text = "Thank you for completing the survey"
        End If

        If AlwaysRadioButton.Checked = False Then
        ElseIf NeverRadioButton.Checked = False Then
        ElseIf SeldomRadioButton.Checked = False Then
        ElseIf SometimesRadioButton.Checked = False Then
        ElseIf UsuallyRadioButton.Checked = False Then
            MessageBox.Show("Please select an answer", "Invalid Answer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        End If


    End Sub

    Private Sub AlwaysRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlwaysRadioButton.CheckedChanged, NeverRadioButton.CheckedChanged, SeldomRadioButton.CheckedChanged, SometimesRadioButton.CheckedChanged, UsuallyRadioButton.CheckedChanged
        Dim always As Integer
        Dim never As Integer
        Dim seldom As Integer
        Dim sometimes As Integer
        Dim usually As Integer

        If AlwaysRadioButton.Checked Then always += 1
        If NeverRadioButton.Checked Then never += 1
        If SeldomRadioButton.Checked Then seldom += 1
        If SometimesRadioButton.Checked Then sometimes += 1
        If UsuallyRadioButton.Checked Then usually += 1



    End Sub
End Class



also Im wondering how i should input the sum of each answer into the printable array should i just input it myself
ex
AnswerGroup(0, 0).AnswerInteger = always


but it says that answerinteger is not a member of windowsapplication1answer

and there is no reason why i had the structure it worked for my last program so i implemented it in this code as well
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3