|
-
Feb 12th, 2008, 03:53 PM
#1
Thread Starter
Hyperactive Member
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.
-
Feb 12th, 2008, 03:58 PM
#2
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:
Dim i As Integer() = New Integer() {n1, n2, n3, n4, n5}
Array.Sort(i)
-
Feb 12th, 2008, 03:59 PM
#3
Re: Yahtzee Variables - Create Sorted Array
VB.Net Code:
Dim intArray() As Integer = {n1, n2, n3, n4, n5}
Array.Sort(intArray)
Edit: dang it
-
Feb 12th, 2008, 04:00 PM
#4
Re: Yahtzee Variables - Create Sorted Array
See, by only typing "i" instead of "intArray", I got my answer in first.
-
Feb 12th, 2008, 04:34 PM
#5
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|