Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8439177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:56:14+00:00 2026-06-10T07:56:14+00:00

I have an array of RichTextBoxes and I would like to initialise them using

  • 0

I have an array of RichTextBoxes and I would like to initialise them using Array.ForEach.

I have made the following attempt with no success:

Dim aRTB(5) as RichTextBox
Array.ForEach(aRTB, Function() New RichTextBox)

This code was the only one to make it past the compiler however it doesn’t initialise any part of the array.

Code which failed to past the compiler includes:

Array.ForEach(aRTB, Function() Return New RichTextBox)
Array.ForEach(aRTB, Function(rtb as RichTextBox) rtb = New RichTextBox)

I realise I could easily set up a a regular loop (For, Do, While) to perform the same action however I would like to see if this way can work.

Thank you for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:56:15+00:00Added an answer on June 10, 2026 at 7:56 am

    I have an array of RichTextBoxes and I would like to initialise them using Array.ForEach.

    You cannot. Array.ForEach performs an action on every element of the array, i.e., it passes the elements of the array to your function a parameter:

    Array.ForEach(aRTB, Sub(rtb as RichTextBox) ...do something with rtb...)
    

    The parameter is ByVal, i.e., you cannot use this to change the contents of the array:

    Array.ForEach(aRTB, Sub(ByRef rtb as RichTextBox) rtb = New RichTextBox())
    ' Yields compilation error: 
    ' Nested sub does not have a signature that is compatible 
    ' with delegate 'System.Action(Of RichTextBox)
    

    Since your array is initially empty, you can’t do anything useful with Array.ForEach on it.

    Sorry, but you will have to use a classic For loop for this:

    For i = 0 To 5
        aRTB(i) = New RichTextBox()
    Next
    

    The 0 To 5 is not a typo… in VB.NET array declarations specify the upper bound, not the size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have array with following strings. first im using explode \n and the output
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
An array is defined of assumed elements like I have array like String[] strArray
I have array like below, Array ( [14289] => Array ( [0] => Karthikeyan
I have array made by function .push . In array is very large data.
i have array like below which is sorted by array_count_values function, Array ( [Session
I have array like below: Array ( [_edit_lock] => Array ( [0] => 1309611144:1
I have array like this: $test = array(20, 30, 40); And I want to
I have array like this: $test = array(20, 30, 40); And I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.