1

I have an assignment to create a program that basically grades a multiple choice test. I have a form with 20 textboxes to accept input (only the letters "a", "b", "c", or "d"), an array with the correct answers, and I created an array to hold all the text boxes:

dim txtboxes() as TextBox = {txtInput1, txtInput2...txtInput20}

I know there's got to be a way to use For Each where the type of control = textbox to iterate over all the textboxes, but I am kind of stuck on actually extracting the values from the textboxes and adding them to an array of their own. I've gotten as far as:

dim txtbox as TextBox
for each txtbox in Controls.OfType(Of TextBox)

which isn't very far at all...

2
  • Well, you are creating an array of TextBox controls, so in theory you don't have to check if they are of type TextBox. You could simply loop through the array. Commented Jan 12, 2017 at 5:26
  • 1
    In addition to @HanletEscaño comment: For Each text In txtboxes.Select(Function(textbox) textbox.Text) ... Commented Jan 12, 2017 at 5:36

1 Answer 1

0

The following code should return the list of textbox values.

Public Sub Convert()
        Dim lstTxtBoxValues As List(Of String) = New List(Of String)
        For Each txtBox As TextBox In txtboxes
            lstTxtBoxValues.Add(txtBox.Text)
        Next
    End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.