Jovitalk - Bon Jovi Fan Community

Jovitalk - Bon Jovi Fan Community (https://drycounty.com/jovitalk/index.php)
-   NBJ - Everything Else (https://drycounty.com/jovitalk/forumdisplay.php?f=10)
-   -   Anybody know VBA? (https://drycounty.com/jovitalk/showthread.php?t=38028)

Adrian 12-12-2006 09:44 PM

Anybody know VBA?
 
I'm working on a VBA project, and I think I remember that a few people here had some expertise in this language. If there's anybody here that could help me with my problem (sorting a 2D array), would you mind if I posted some code?

Thanks,

Adrian

Edwin 12-13-2006 08:29 PM

Well, I could always try....

Adrian 12-13-2006 08:43 PM

If you could help out, that's great.

I got a modification of my code (a bubble sort that sorts a one-dimensional array) which now sorts a two dimensional array. The problem is, it doesn't work. I barely understand bubble sorts as it is, and I can't figure out why the second one won't sort. Here's the code:

Code:


Public Function SortArrayOfZips(location() As Variant) As Variant()
    Dim First As Integer, Last As Integer
    Dim i As Integer, j As Integer
    Dim Temp As String
   
    First = LBound(location)
    Last = UBound(location)
   
For i = First To Last
For j = First To (Last - i - 1)
If location(j, First) > location(j + 1, First) Then
Temp = location(j, 1)
location(j, 1) = location(j + 1, 1)
location(j + 1, 1) = Temp
End If
Next j
Next i
   
SortArrayOfZips = location()
End Function

Thanks much in advance!

Adrian

Edwin 12-14-2006 09:48 PM

Mind that bubble sort only sort a one dimensional array

1 - 5 - 4 - 7
2 - 5 - 9 - 1
8 - 4 - 2 - 3

How should this 2D array be sorted according to you?

Adrian 12-15-2006 03:11 AM

Thanks. The professor was pretty specific that the bubble sort could be adapted...I don't know though.

The 2D array (it may contain numbers or strings) should be run through the sort, and come out with the first element sorted in ascending order, the second element organized on the first element. So:
1-2
3-4
2-3
4-5
would come out:
1-2
2-3
3-4
4-5
Thanks much! I really appreciate it.

Adrian

Thomas Anderson 12-15-2006 03:25 AM

I remember doing bubble sorts in maths, one of the many things I've forgotten since, due to it having no use to me, in the 3 years since I finished college.

Edwin 12-15-2006 03:17 PM

I don't know enough of VBA concepts to implement a bubble sort.
The way I see it, you just implement a regular bubble sort. The only modification is that you surround it with a for-loop which bubblesort each column. That's why I don't get this statement:
Code:

For j = First To (Last - i - 1)
Since integer i seems the outer for loop which should iterate over the columns, while the inner for-loop (or loops) does an actual bubblesort. Otherwise, consult http://en.wikipedia.org/wiki/Bubble_sort because this is far too technical for this board :).


All times are GMT +2. The time now is 02:17 PM.

Powered by vBulletin® Version 3.8.11.
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.