Jovitalk - Bon Jovi Fan Community
Home Register Members FAQ
 

Anybody know VBA?

NBJ - Everything Else


Reply
 
Thread Tools
  #1  
Old 12-12-2006, 09:44 PM
Adrian's Avatar
Adrian Adrian is offline
Senior Member
It's my post
 
Join Date: 31 Oct 2002
Location: Wisconsin, USA
Age: 35
Gender: male
Posts: 4,805
Default 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
__________________


What Part Of My Body Hurts The Most
What part of my soul is crying
For crying out loud
What part of my heart is beating
Faster than the speed of love
Is this the way that it's supposed to be
What Part Of My Body Hurts The Most
Come a little bit closer
Come here now
Let's see
Reply With Quote

  #2  
Old 12-13-2006, 08:29 PM
Edwin's Avatar
Edwin Edwin is offline
Senior Member
Dry County
 
Join Date: 29 Jul 2002
Location: The Netherlands
Gender: male
Posts: 1,831
Default

Well, I could always try....
__________________
Only you can turn the page
And close the curtain on this empty stage
Reply With Quote
  #3  
Old 12-13-2006, 08:43 PM
Adrian's Avatar
Adrian Adrian is offline
Senior Member
It's my post
 
Join Date: 31 Oct 2002
Location: Wisconsin, USA
Age: 35
Gender: male
Posts: 4,805
Default

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
__________________


What Part Of My Body Hurts The Most
What part of my soul is crying
For crying out loud
What part of my heart is beating
Faster than the speed of love
Is this the way that it's supposed to be
What Part Of My Body Hurts The Most
Come a little bit closer
Come here now
Let's see
Reply With Quote
  #4  
Old 12-14-2006, 09:48 PM
Edwin's Avatar
Edwin Edwin is offline
Senior Member
Dry County
 
Join Date: 29 Jul 2002
Location: The Netherlands
Gender: male
Posts: 1,831
Default

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?
__________________
Only you can turn the page
And close the curtain on this empty stage
Reply With Quote
  #5  
Old 12-15-2006, 03:11 AM
Adrian's Avatar
Adrian Adrian is offline
Senior Member
It's my post
 
Join Date: 31 Oct 2002
Location: Wisconsin, USA
Age: 35
Gender: male
Posts: 4,805
Default

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
__________________


What Part Of My Body Hurts The Most
What part of my soul is crying
For crying out loud
What part of my heart is beating
Faster than the speed of love
Is this the way that it's supposed to be
What Part Of My Body Hurts The Most
Come a little bit closer
Come here now
Let's see
Reply With Quote
  #6  
Old 12-15-2006, 03:25 AM
Thomas Anderson's Avatar
Thomas Anderson Thomas Anderson is offline
Friends will be friends
Bounce
 
Join Date: 15 Aug 2002
Location: Merseyside, England
Age: 36
Gender: male
Posts: 30,116
Default

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.
__________________
Reply With Quote
  #7  
Old 12-15-2006, 03:17 PM
Edwin's Avatar
Edwin Edwin is offline
Senior Member
Dry County
 
Join Date: 29 Jul 2002
Location: The Netherlands
Gender: male
Posts: 1,831
Default

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 .
__________________
Only you can turn the page
And close the curtain on this empty stage
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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.