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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:12:23+00:00 2026-06-13T03:12:23+00:00

I am making a program that outputs random numbers and then organizes them. I

  • 0

I am making a program that outputs random numbers and then organizes them.

I am organizing the numbers so later I can add code to tell the user how many matching numbers he or she has received.

The program compiles fine, but then when I run the exe, after the first line of random numbers is outputted it crashes. The error I receive is:

the index is outside the boundaries of the array.

Any help at all would be gratefully appreciated.

Option Explicit On
Option Strict On

Imports System

Module Yahtzed

Sub Main()

    Randomize()
    Dim Index, Values, NumberOfPlayers,Temp as Integer
    Dim order(index) as integer
    Dim Last As Integer = 0 'to Order.Length-2
    Console.Write("How many people will be playing Yahtzed?: ")
    NumberOfPlayers = convert.toint32(Console.Readline)
    Do while NumberOfPlayers > 0
        Index = 0
        Do until index = 5
            Values = CInt(Int((6 * Rnd()) + 1))
            Console.Write(" "&values)
            Index += 1
        Loop
        Do Until Index = 0
            If Order(Index + 1) < Order(index)
                Temp = Order(Index + 1)
                Order(Index + 1) = order(index)
                Order(index) = Temp
                Console.WriteLine(Order(Index))
            End if
            index -= 1
        loop
        Console.Writeline
        NumberOfPlayers -= 1
        Console.Writeline()
    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-13T03:12:24+00:00Added an answer on June 13, 2026 at 3:12 am

    The code doesn’t really make sense as it is now. You create some random numbers, then you throw them away, and sort an array that never has been assigned anything. Also, the array only has one item, so it would not be able to hold the random values.

    I think that you want to declare the array for five items, not one (as index is zero by the time you create the array):

    Dim order(4) As Integer
    

    Then put the random numbers in the array instead of putting them in a variable where each random number will replace the previous one:

    Index = 0
    Do until index = 5
      order(index) = CInt(Int((6 * Rnd()) + 1))
      Console.Write(" " & order(index))
    Loop
    

    When you sort the array, you start looking at index 6 (as the variable index is 5), which is outside the array. You would want to start at one item from the last in the array (i.e. at index 3). Then you loop until index is -1, otherwise you won’t be comparing the two first items in the array.

    Also, you have to continue sorting until there are no more swaps, just going through the array once doesn’t make it sorted:

    Dim swapped as Boolean = True
    Do While swapped
      index = 3
      swapped = False
      Do Until index = -1
        If order(index + 1) < order(index)
          temp = order(index + 1)
          order(index + 1) = order(index)
          order(index) = temp
          swapped = True
        End if
        index -= 1
      Loop
    Loop
    

    This sorting algorithm is called Bubble Sort.

    There is also sorting built into the framework, if you want to use that instead:

    Array.Sort(order)
    

    If you would write out the values while sorting, you would get them several times over, so you do that after they are sorted:

    index = 0
    Do until index = 5
      Console.Write(" " & order(index))
    Loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was making a program that rounds up numbers with various decimal places, so
I am making a program that adds two binary numbers (up to 31 digits)
I am making a program that will run a persons C++ code from PHP.
Hello making a small program that reads a text file then creates an ouput
I am trying to learn python and am making a program that will output
I am making a program that automates the seperation of a csv file. We
I am making a program that graphs a line based on data inputted by
I am currently making a program that will send an email if the date
I noticed while making a program that a lot of my int type variables
I'm making a program that communicate with certain patient monitor using C sockets. I'm

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.