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 6806671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:44:22+00:00 2026-05-26T19:44:22+00:00

How to initialize a multidimensional array by loop operation in VB .Net? I have

  • 0

How to initialize a multidimensional array by loop operation in VB .Net?

I have some arrays called ‘Room’, ‘Subject’, and ‘Population’.

  1. Array ‘Room’, contains the name of the room, i.e.

    {"RoomA", "RoomB"}
    
  2. Array ‘Subject’, contains the name of the subject, i.e.

    {"English", "Mathematic", "Physics", "Biology"}
    
  3. Array ‘Population’ is a multidimensional-array that contains randomize room taken from array ‘Room’. i.e. {("RoomA", "RoomA", "RoomA", "RoomA"), ("RoomA", "RoomA", "RoomA", "RoomB"), ("RoomB", "RoomA", "RoomB", "RoomB"), .....}. The length of the array is based on the generate value and the length of the subject.

I’ve tried this code but it’s no luck:

Dim i, j As Integer
Dim TotalSubject As Integer = Subject.Count() 
Dim TotalRoom As Integer = Room.Count() 

Dim Population(,) As String
ReDim Population(generate, TotalSubject) 'Give the 'Population' bound

For i = 0 To generate
    For j = 0 To TotalSubject
        Dim Randomize As Integer = Rnd() * TotalRoom
        Population(i, j) = Room(Randomize) '----- ERROR HERE -----'
    Next j
Next i

But while I’m execute the code, it got error message sounds “IndexOutOfRangeException was unhandled” pointed to the above marked ‘ERROR HERE’ code. Can you help me solved this problem?

This code is for initialize the starting value use Compact Genetic Algorithm for an optimization problem to optimize the usage of the classroom. Does anyone know this method? If yes, would you like to share the knowledge with me? I’ve tried to search several material for that but still can’t implement it onto a code.

  • 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-05-26T19:44:22+00:00Added an answer on May 26, 2026 at 7:44 pm

    The error is with Room(Randomize) not with your array.

    You state that Room is an Array but your code includes Room.Count(). Arrays have a Length, not a count. Therefore my guess is that Room is some sort of collection. Next, your random number Randomize (assigned by Rnd() * TotalRoom) has a range of 0 to TotalRoom, where TotalRoom is equal to Room.Count(). So if your collection is zero based then you are getting index out of bound when you randomly generate a value equal to your collection count. And if your collection is 1 based, then you are getting index out of bound when you randomaly generate a 0.

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

Sidebar

Related Questions

I'm trying to create a form that contains these multidimensional arrays: <input type=text name=cost[1][desc]>
I need to know how to initialize array of arrays in C#.. I know
Initialize an array of arrays: M = [[]]*(24*60/5) Append the number 2 to the
I am trying to initialize a multidimensional array. Here is my syntax; this does
When ever I try to initialize a multidimensional array I get the following error:
How could I simple initialize a multidimensional C-array with 0 elements like this: int
I have a class that contains a few multi-dimensional arrays. I am trying to
I want to create a multidimensional array and initialize it with copies of a
To initialize an int array with all zeros, do I need to use: int
How can I initialize a const / static array of structs as clearly as

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.