
-----------------------------------
JKJones
Sun Dec 05, 2010 10:10 pm

What is wrong with my subroutine
-----------------------------------
Hello i'm making minesweeper and i thought itd be cool to make a high score board so the way i did it is  every time they win the time it adds there score to an array. I redim the array to add 1 to the bounds of the array every time they win so it can store all the wins. Then i made a new form that has 1 to 5 listed and beside 1 is "highscore(1)"
beside 2 is "highscore(2)" and so on. The only thing i was left to do was rearange the array so "highscore(1)" is the lowest and then 2 in the next lowest and so on. I wasn't able to find a function or subroutine that would do this correctly for me so i decided to make my own. This is what i came up with...

Private Sub LowHighSort(ByVal array As System.Array)
        Dim switchhold As Double
        Dim highval As Double
        highval = UBound(array)
        For j As Double = 0 To 100
            Dim k As Double
            k = j
            For i As Double = 0 To (highval - 1)
                Dim e As Double
                e = i
                If array(e) > array(e + 1) Then
                    switchhold = array(e)
                    array(e) = array(e + 1)
                    array(e + 1) = switchhold
                Else
                    If array(e) < array(e + 1) Then
                    Else
                        If array(e) = array(e + 1) Then
                        End If
                    End If
                End If
            Next
        Next
    End Sub


I'd say i did something wrong because it will randomly have the highest number at the top or i don't know it won't work could any body edit it so that it will work indefinitely help would be greatly appreciated thnks i'm using 2005 by the way

-----------------------------------
DemonWasp
Sun Dec 05, 2010 11:28 pm

RE:What is wrong with my subroutine
-----------------------------------
You seem to be trying to sort, and you've invented some kind of bizarre sort on your own. I highly recommend you do the following two things:

1. Look for existing "sort" algorithms written into your VB platform. I recall VB being a ... deficient ... platform, but not so bad that it wouldn't have a relatively accessible sorting algorithm.

2. If that fails, look up Bubblesort on Wikipedia and try to translate that algorithm into VB.


Actually, I can probably translate relatively well:
Note: I'm using ByRef, you were using ByVal. It's occurred to me that this is probably the problem: you may be sorting a copy of the data you passed in to your method.

-----------------------------------
JKJones
Mon Dec 06, 2010 1:27 am

RE:What is wrong with my subroutine
-----------------------------------
Thanks i had tried others before they didn't do what i wanted. I tried yours and got pretty much the same results and i made sure that its the sort and not some other part of the program that is messing up. (P.S i searched bubble sort its basically the same thing i was trying to implement)

-----------------------------------
TerranceN
Mon Dec 06, 2010 4:37 pm

RE:What is wrong with my subroutine
-----------------------------------
Try taking 5 or so out of order integers, then go through your subroutine by hand/on paper.

Edit: I could have swore there was another post before mine that I was replying to... Maybe I'm losing my mind, maybe I'm switching between tabs too fast, IDK.

-----------------------------------
JKJones
Mon Dec 06, 2010 4:53 pm

RE:What is wrong with my subroutine
-----------------------------------
There was but i deleted it because the whole i figured that out. And if it makes any difference i realized my array was declared as a string instead of a double so i changed that but am still getting the same problems. I'll try going through it on paper.

Edit i went through it on paper it got through it and worked easily which of course isn't the case in reality

Um im not sure how but somehow i made it work thnks guys
