|
-
Jul 28th, 2014, 10:25 AM
#8
Re: How to order array results??
I don't know. I was trying to interpret your code.
Perhaps your code was pseudo code and didn't actually spell out what cars(i) was, or mean.
But in the code you linked to, you had the cars() array declared as a Decimal type, which means each element of the array can hold a single value.
That is why the code makes no sense because you set it to two different things in different parts of the code.
As far as my code example goes, it was just an example I wrote earlier, before you posted your code. Since Ident had posed a question by the time I had it written, I waited to see what your response would be before I posted it.
I didn't make cars a single value, I made it an array and assigned nine values to it so the example code would have something to sort, and assuming the order of the array as set is the order of the cars by number (which your "cars(i) = i+1" would seem to indicate), the example shows how to create an "index" array, which serves both as the car number (the index value), and the sorted array (you sort the indexes by the value of what they point to).
This gives you an array you can loop through in order from 0 to whatever, and find which car is at that spot (the value at that item of the array), and the value associated with that car (using the value from the index array to index into the cars array).
This was an effort to work with what you have, but in reality, you should probably have a car class that holds all the things you need to know about a car, and have an list of instances of that class.
I gave it a shot, but if you are a massive noob then perhaps the task you've jumped into is a bit more involved than you should be dealing with right now. I have limited time, so can possibly answer a specific question on a particular point, but I definitely don't have the time to be a tutor about VB.Net in general.
Some have taking on that task and provide various tutorials, but I'll probably have to let this go as I am a bit swamped at the moment.
 Originally Posted by TheKian
... If it's supposed to be costs per year for each car how to I change it so each value is one that has been previously calculated. Thanks
Just remove my declaration for cars(i), use your code to populate the array, then either use the code in the button click to process the array, or put that code in a sub that you can call. It is just an example. It is up to you to understand what it is doing then pull what you need from the example and tailor it to your situation.
You can see the order of the values in the source code
{4.23, 7.23, 2.58, 5.67, 3.28, 9.12, 7.25, 8.15, 4.36}
So cars(0) is 4.23 and cars(1) is 7.23, etc...
If you run the code you can see the sorted output, note below that car 0 is still 4.23 and car 1 is 7.23.
Code:
Car 2, 2.58
Car 4, 3.28
Car 0, 4.23
Car 8, 4.36
Car 3, 5.67
Car 1, 7.23
Car 6, 7.25
Car 7, 8.15
Car 5, 9.12
Last edited by passel; Jul 28th, 2014 at 10:41 AM.
Tags for this Thread
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
|