Results 1 to 5 of 5

Thread: Yahtzee Variables - Create Sorted Array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Yahtzee Variables - Create Sorted Array

    In a Yahtzee project, I have 5 integer vairabls n1, n2, n3, n4 and n5. I need a function that creates and uses a sorted integer array i(0 to 5) from the variables listed above. The 5 variables are form-level variables. The array will only be used in the function.

    I know there's Dim i as arraylist and there's i().sort. I'm just not sure how to use them.

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: Yahtzee Variables - Create Sorted Array

    Just put them in an array and call the Array.Sort(). By default, the Sort method orders numbers from lowest to highest, so you don't need to do anything special with it.

    In your function:

    vb Code:
    1. Dim i As Integer() = New Integer() {n1, n2, n3, n4, n5}
    2.  
    3. Array.Sort(i)

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Yahtzee Variables - Create Sorted Array

    VB.Net Code:
    1. Dim intArray() As Integer = {n1, n2, n3, n4, n5}
    2.         Array.Sort(intArray)

    Edit: dang it
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: Yahtzee Variables - Create Sorted Array

    See, by only typing "i" instead of "intArray", I got my answer in first.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Yahtzee Variables - Create Sorted Array

    That's certainly easier than the nested loop/ bubble sort stuff I was doing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width