How to initialize a multidimensional array by loop operation in VB .Net?
I have some arrays called 'Room', 'Subject', and 'Population'.
Array 'Room', contains the name of the room, i.e.
{"RoomA", "RoomB"}Array 'Subject', contains the name of the subject, i.e.
{"English", "Mathematic", "Physics", "Biology"}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.