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

  • Home
  • SEARCH
  • 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 8642401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:46:01+00:00 2026-06-12T11:46:01+00:00

This is just a piece of my code, but it’s causing me issues. The

  • 0

This is just a piece of my code, but it’s causing me issues. The intended purpose of the code is to take the users input and make it the size of the array. However, it is giving me the error ‘index was outside bounds of array’ not matter what value I enter.

Here is the code:

Option Explicit On
Option Strict On

Imports System

Module numbers
    Sub Main()
        'index decides number of candidates.
        Dim index as integer
        Dim candidate(index) as integer

        Console.Write("Please enter the number of candidates in the election: ")
        index=Convert.toInt32(Console.Readline())

        Do Until candidate(index) >= 0
            Console.Write(" Enter the name of candidate: ")
            candidate(index)=Convert.toInt32(Console.Readline())

            candidate(index) -=1
        Loop
    End Sub
End Module
  • 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-12T11:46:03+00:00Added an answer on June 12, 2026 at 11:46 am

    You’ve got a few problems here.

    Firstly, you need to initialise your array after you know how big it is.

    Secondly, you will find a For loop is easier than a Do loop for implementing the logic, as you don’t need to keep track of the loop counter manually.

    Finally, you are converting your candidate names to an integer. Most people’s names are not numeric!

    Sub Main()
        'index decides number of candidates.
        Dim index as integer
    
        Console.Write("Please enter the number of candidates in the election: ")
        index=Convert.toInt32(Console.Readline())
    
        ' We now know how big the array needs to be so you can initialise it.
        Dim candidate(index) as integer
    
        ' We use a For loop so that we don't have to worry about the 
        ' loop counter ourselves.
        For i As Integer = 0 to (index - 1)
            Console.Write(" Enter the name of candidate: ")
            ' Your candidate names appear to be an integer - 
            ' Surely that's not right??! I think you meant
            ' candidate(i) = Console.Readline()
            candidate(i)=Convert.toInt32(Console.Readline())
        Next
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just realized that this piece of code works well in Firefox but not
just trying to test for equality in this piece of code, but getting a
I just wrote this piece of code but I'm not quite happy about it.
I have just solved another problem regarding the same piece of code but I
I just wrote this piece of code to represent this error that is killing
I've just replaced this piece of code: foreach( var source in m_sources ) {
I just saw this piece of javascript code at Facebook: javascript:eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return
I am just using this piece of code in viewDidLoad method. It only opens
I've just tried this piece of code: struct FaceOfPast { virtual void Smile() =
I fear this just may not be possible, but I'm trying to create a

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.