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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:30:49+00:00 2026-06-13T04:30:49+00:00

I am trying to sort a multidimensional array, but am not sure if this

  • 0

I am trying to sort a multidimensional array, but am not sure if this is the correct way to go about it. So far, I am getting my 5 numbers in the multidimensional array and then moving them into a single dimensional array and using array sort. Does know a better way ? or have ideas on how to improve mine? Also , the code currently isn’t working in the sorting area, it gives me an index out of array error.

Any help will be appreciated. Thanks in advance

Module q
    Sub Main()
        Randomize()
        Dim Player,RandomNumber,NumberOfPlayers,Index As Integer
        Dim Roll as Integer = 0
        Console.Write("How many people will be playing Yahtzed?: ")
        Player = convert.toint32(Console.Readline)
        NumberOfPlayers = Player
        Dim Game(Player,5) As Integer
        Do until Player = 0
            Console.Write("User")
            Roll = 0
            Do until Roll = 5
                RandomNumber = CINT(Int((6 * Rnd()) + 1))
                Game(Player,Roll) = RandomNumber
                Roll += 1
                Console.Write(" "&RandomNumber)
            Loop 
            Player -= 1
            Console.Writeline()
        Loop 
        Player = NumberOfPlayers
        Do until Player = 0
            Dim Ordering(5) as Integer
            Roll = 0
            Do until Roll = 5
                Ordering(Index) = Game(Player,Roll)
                Roll += 1
                Index += 1
                Array.Sort(Ordering)
            Loop
        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-13T04:30:51+00:00Added an answer on June 13, 2026 at 4:30 am

    The idiomatic way of iterating arrays is done using a For-statement

    Const  NPlayers As Integer = 5, NRolls As Integer = 5
    
    Dim game = New Integer(NPlayers - 1, NRolls - 1) {}
    Dim randomizer As New Random()
    Dim randomNumber As Integer
    
    For p As Integer = NPlayers - 1 To 0 Step -1
        For r As Integer = 0 To NRolls - 1
            randomNumber = randomizer.[Next](10)
            game(p, r) = randomNumber
        Next 
    Next
    

    The array indexes always go from 0 to arraysize-1.

    The size of your Ordering array would be NPlayers * NRolls

    Dim Ordering(NPlayers * NRolls - 1) As Integer
    

    Yours is too short. Therefore you get an exception.


    Integer random numbers can be created using the Random class

    Dim randomizer As New Random()
    Dim randomNumber As Integer
    
    ...
    
    randomNumber = randomizer.[Next](10)
    

    This creates random numbers between 0 and 10. Create the randomizer only once and then get the next random number by calling the Next method.

    (You must put the Next method between brackets, because Next is a keyword in VB.)


    UPDATE

    I assume that you want to sort the rolls per player. The easierst way to accomplish this is to use a jagged array instead.

    Const  NPlayers As Integer = 5, NRolls As Integer = 5
    
    Dim game = New Integer(NPlayers - 1)() {}
    For p As Integer = NPlayers - 1 To 0 Step -1
        game(p) = New Integer(NRolls - 1) {}
        For r As Integer = 0 To NRolls - 1
            game(p)(r) = randomizer.[Next]()
        Next
        Array.Sort(game(p))
    Next
    

    But the you will have to access the rolls with game(p)(r) instead of game(p,r).

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

Sidebar

Related Questions

Trying to sort by this multidimensional array by screen name: //Looping through this for
I'm trying to sort a multidimensional array in objective-c i know that i can
Trying to sort this array of objects according to (1) depth and (2) weight,
I am trying to sort a two-dimensional array by a timestamp column Descending. This
I'm trying to sort the employees object array by age and i'm getting the
I'm trying to sort a multidimensional array by multiple keys, and I have no
I am trying to sort a multidimensional JSON array (called jsontest here) using JQuery
Im trying to sort a listbox full of numbers numerically. Why doesnt this work?
Been trying to sort this for over a day now, and I am sure
I am having a hard time trying recursively sort a multidimensional array on its

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.