Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   VBScript - Sorting (http://www.programmingforums.org/showthread.php?t=10907)

randum77 Aug 1st, 2006 8:03 AM

VBScript - Sorting
 
In VBScript can the Array.Sort method be used? If not, do i have to build a loop to do the work? If that ends up being the case, how would I build a loop to do that?:confused: Just basic guidence would be cool.

melbolt Aug 1st, 2006 12:27 PM

vbscript lacks a sort function for arrays.

what can you do? here are your options, i recommend #1
1) use Javascript to sort an array for you. you can call a javascript function from within your vbscript like so

:

<script language=JScript runat=server>
function SortVBArray(arrVBArray) {
return arrVBArray.toArray().sort().join('\b');
}
</script>

<%
Function SortArray(arrInput)
SortArray = Split(SortVBArray(arrInput), Chr(8))
End Function
%>


here's some more helpful stuff at this link
http://www.4guysfromrolla.com/aspfaq...Q.asp?FAQID=89

2)build your own - this works too but you're reinventing the wheel

3) use one someone else built in vbscript, a google search will turn this up, this works too.

randum77 Aug 2nd, 2006 7:17 AM

Melbolt, thank you for the info. What i ended up doing was using one that i found on a page, and just modified it to fit my needs. Let me show you what I used. I hate the variables used, but i eventually figured it out.

:

for i = 0 to ln - 1
    for j = i + 1 to ln
        if (fa(i,2) < fa(j,2)) then 'fa(i,0) = fa(j,0) and
            sn = fa(i,0)
            s = fa(i,1)
            fd = fa(i,2)
          mn = fa(i,3)
            fa(i,0) = fa(j,0)
            fa(i,1) = fa(j,1)
            fa(i,2) = fa(j,2)
          fa(i,3) = fa(j,3)
            fa(j,0) = sn
            fa(j,1) = s
            fa(j,2) = fd
          fa(j,3) = mn
        end if
    next


I cut and commented out the spare code. It bassically just sorts by the 3rd feild in the array, which is the second column. It works pretty good for what we were needing here at work.

I do like that java insert idea though. I'll have to take advantage of that here soon.


All times are GMT -5. The time now is 4:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC