Solved

How can I loop through multiple choice questions and check what ones have been answered?

Posted on 2004-10-11
3
218 Views
Last Modified: 2010-08-05
How can I loop through multiple choice questions and check what ones have been answered?

Say I have radioList questions

RadQ1
   a/ Possible Answer
   b/ Possible Answer
   c/ Possible Answer
   d/ Possible Answer
RadQ2
   a/ Possible Answer
   b/ Possible Answer
   c/ Possible Answer
   d/ Possible Answer
RadQ3
   a/ Possible Answer
   b/ Possible Answer
   c/ Possible Answer
   d/ Possible Answer
RadQ4
   a/ Possible Answer
   b/ Possible Answer
   c/ Possible Answer
   d/ Possible Answer
RadQ5
   a/ Possible Answer
   b/ Possible Answer
   c/ Possible Answer
   d/ Possible Answer

Ok then Possible answer is the DataTextField and behind the scenes I have a,b,c & d set to either Correct or Incorrect as the DataValueField.

How can I check which questions have been answered. I have all the RadQ1,RadQ2 ID's displayed in labels so that they can be referred to by their ID...etc

I would like to basically fill in any unanswered questions automatically with an incorrect selections.

This question is very urgent and thus I would greatly appreciate your input

Thanks very much

Paul G

0
Comment
Question by:pgilfeather
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 12275849
Here is a sample in a Class that you could use as you loop thru the controls (RadioButtons,etc.)....

Imports System.Windows.Forms
Public Class clsControlID
    Inherits System.Windows.Forms.Control
    ' Return a reference to the control with the specified name,
    '  searched into the specified container and its sub-controls
    ' Note: it requires the GetAllControls function
    '
    ' Example: get a reference to a Label named "lblTest", and set its Text property
    '  DirectCast(FindControl("lblTest", Me), Label).Text = "Found!"

    Public Overloads Shared Function FindControl(ByVal ctlName As String, ByVal container As Control) As Control
        ' retrieve an array with all the controls of the
        ' input container controls, and its sub-controls
        Dim ctls() As Control = GetAllControls(container)
        Dim ctl As Control
        For Each ctl In ctls
            ' loop through the returned controls,
            ' and return the one with the
            ' wanted name, if present
            If ctl.Name = ctlName Then Return ctl
        Next
    End Function
    Public Overloads Shared Function FindControl(ByVal singleControl As Control, ByVal container As Control) As Control
        Dim ctls() As Control = GetAllControls(container)
        Dim ctl As Control
        For Each ctl In ctls
            If TypeOf (singleControl) Is TextBox Then
                If ctl.Name Is singleControl.Name Then Return ctl
            End If
        Next
    End Function
    ' Returns an array with all the controls in the specified container control and
    ' its child containers
    ' Example:
    '    ' print the name of all the controls on the form and its child container
    ' controls
    '    Dim ctl As Control
    '    For Each ctl In GetAllControls(Me)
    '        Debug.WriteLine(ctl.Name)
    '    Next
    Shared Function GetAllControls(ByVal container As Control) As Control()
        Dim al As New ArrayList
        Dim ctl As Control
        For Each ctl In container.Controls
            GetAllControlsHelper(ctl, al)
        Next
        Return al.ToArray(GetType(Control))
    End Function

    Shared Sub GetAllControlsHelper(ByVal container As Control, ByVal al As ArrayList)
        ' add this control to the ArrayList
        al.Add(container)
        ' add all its child controls, by calling this routine recursively
        Dim ctl As Control
        For Each ctl In container.Controls
            GetAllControlsHelper(ctl, al)
        Next
    End Sub
End Class
0
 

Author Comment

by:pgilfeather
ID: 12275939
Thanks but this looks a bit over complicated, I'm sure there must be a much simpler way to do what I've asked. Also you have not made any regerence to my example.

Kind Regards

Paul G
0
 
LVL 10

Accepted Solution

by:
Hans Langer earned 500 total points
ID: 12278219
Hi,
You can use GroupBox for each cuestion and ask this way if it was answered:

'  me.grpQ1 = GroupBox for question1
'  And put all answer of question 1 into GroupBox1 and
'  Do the same thing with others questions.

Dim oRadioButton As RadioButton

For Each oRadioButton In grpQ1.Controls
      If oRadioButton.Checked Then MsgBox("Question 1 Answered")
Next

For Each oRadioButton In grpQ2.Controls
      If oRadioButton.Checked Then MsgBox("Question 2 Answered")
Next

Etc...

GL
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with error in Query 2 39
VB.NET String Settings and Temp Folder Question 3 71
Vb.net threads keep increasing 2 50
vb.net convert long time to mm:ss 23 22
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question