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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:29:17+00:00 2026-06-12T01:29:17+00:00

I am trying to generate a population for a GA. I used a 2d

  • 0

I am trying to generate a population for a GA. I used a 2d array to help generate a population. First the user will enter the population size and then the chromosome length, into a UserForm.

My variables:

Dim Generation As Integer
Dim Chromolength As Integer
Dim varchromolength As Integer
Dim Poparr() As Integer

Then I fetch the values from the UserForm:

PopSize = PopulationSize.value
aVariables = AOV.value          'assign userform value entered to this variable
varchromolength = Chromolengthentered.value    'assign userform value entered to this   variable
Chromolength = varchromolength * aVariables   'Chromosome length equals the length of     each varaible chromosome combined

The coding where the error occurs:

For i = 1 To PopSize           
    For j = 1 To Chromolength       
        If Rnd < 0.5 Then           
            Poparr(i, j) = 0   'assign o to gene
        Else
            Poparr(i, j) = 1   'assign 1 to gene     
        End If
    Next j
Next i
  • 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-12T01:29:18+00:00Added an answer on June 12, 2026 at 1:29 am

    Based on your code, you never assign the dimensions of the array. To do so, insert this line before your for loop, after setting the values of PopSize and ChromoLength.

    Redim Poparr(1 to PopSize, 1 to ChromoLength)
    

    Unnecessary details: You could just run Redim Poparr(PopSize, ChromoLength) but that would result in arrays that were 0 to Popsize etc… unless you add Option Base 1 to the top of your module. The default base for arrays is 0. I feel that it is better to explicitly indicate the lowerbound and upperbound of your array because the default can be 0 or 1 depending on the context.

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

Sidebar

Related Questions

Trying to generate Rails API documentation, but running into errors: $ rake doc:rails rake
I am trying to generate all possible keypad sequences (7 digit length only right
I am trying to generate a Sandcastle help file for a website. In the
I am trying to generate 4 triangles based on user inputted parameters for a
I'm trying to generate a Java Bean Skelleton from a WSDL (actually this will
Trying to generate JavaDocs for the Android lint-cli project on Mac 10.7 Keep getting
Im trying to generate a color gradient using ColdFusion. My current code below works
I trying to generate an XML document which is around 23 to 30 MB,
I'm trying to generate a report of the activities that users have done within
I'm trying to generate the following html code using cl-who: <html> <body> <div id=cnt_1></div>

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.