Tuesday, March 20, 2007

Sorting Arrays in VBScript

Here's a simple function to sort your simple array. Hope it makes your life simpler.

'****************************************************************************************** ' SortArray - sort a string or numeric array
'****************************************************************************************** function SortArray(arrShort)
dim i, j, temp
for i = UBound(arrShort) - 1 To 0 Step -1
for j= 0 to i
if arrShort(j)>arrShort(j+1) then
temp=arrShort(j+1)
arrShort(j+1)=arrShort(j)
arrShort(j)=temp
end if
next
next
SortArray = arrShort
end function

42 comments:

Anonymous said...

Thanks, awesome script!

Anonymous said...

Very nice and clean. I am wondering, I would like to track the sorting, i.e, when an item is sorted, I would like to track its original index to the sorted index. Any hints on this?

Thanks again!

Belgium said...

Here is a solution to sort numeric ...



ArrayUbound = UBound(YourArray)

'Display the Array BEFORE numeric sorting
For I = 0 to (ArrayUbound)
Response.Write(YourArray(I) & "
")
Next

'The actual sort process
For I = 0 to ArrayUbound
TempVAR_1 = 0
TempVAR_2 = 0
For P = 0 to ArrayUbound
If int(YourArray(I)) < int(YourArray(P)) Then
TempVAR_1 = int(YourArray(I))
TempVAR_2 = int(YourArray(P))
YourArray(I) = TempVAR_2
YourArray(P) = TempVAR_1
End IF
Next 'P
Next 'I

'Display the Array AFTER numeric sorting
For I = 0 to (ArrayUbound)
Response.Write(YourArray(I) & "
")
Next

Anonymous said...

Is there a way to modify this to sort a list of files like 1L1, 1L20, 1L10, 1L2. This code sorts these files like so: 1L1, 1L10, 1L2, 1L20. The desired response would be: 1L1, 1L2, 1L10, 1L20. Any help?

Anonymous said...

I am the sort of hombre who passions to taste unprecedented things. Presently I'm constructing my private photovoltaic panels. I'm making it all by myself without the assistance of my men. I'm using the net as the only path to acheive that. I saw a very awesome website which explains how to make pv panels and wind generators. The site explains all the steps involved in solar panel construction.

I'm not sure about how precise the information given there iz. If some people over here who had xp with these things can have a look and give your feedback in the site it would be grand and I would highly treasure it, because I truly enjoy solar panel construction.

Tnx for reading this. You people rock.

Anonymous said...

Cartier, Celine, Chanel, Chloe, Christian Dior, Christian Louboutin, Coach, Dior Homme, Dolce & Gabbana, Fendi, Giuseppe Zanotti, Givenchy, Gucci, Hermes, Jimmy Choo, Lancel, Lanvin, Loewe, Louis Vuitton, Manolo Blahnik, Marc Jacobs, Marni, Miu Miu, Mulberry, Prada, Salvatore Ferragamo, Thomas Wylde, Tory Burch, Valentino, Versace, Vivienne Westwood, Yves Saint Laurent, 3.1 Phillip Lim, Alexander McQueen, Alexander Wang, Anya Hindmarch, Balenciaga, Bally, Bottega Veneta, Burberry

Anonymous said...

Hey guys, - for several of you who gamble a couple dollars to win a big jackpot: here is a good web site which allows Canadian players and gives away 100% money back casino bonus and 20$ free casino bonus to every new player. They also have blackjack, video poker, slot machines, roulette & other 300+ web casino games available.
This Sunday I won almost 1K there, and their cashout was smooth and quick. Strongly recommended:
new no deposit online casinos

Myke Black said...

the numerical sort array above only caters for whole numbers, if you have doubles or floats this will not work as well. This function works for mixed arrays too which may have strings, floats and integer types in the same array:

function sortNumericalArray(arrShort)

for i = UBound(arrShort) - 1 To 0 Step -1
for j= 0 to i
jnum = 0
inum = 0
if isnumeric(arrShort(j+1)) and arrShort(j+1) <> "" then jnum = cdbl(arrShort(j+1))
if isnumeric(arrShort(j)) and arrShort(j)<> "" then inum = cdbl(arrShort(j))
if inum>jnum then
temp=arrShort(j+1)
arrShort(j+1)=arrShort(j)
arrShort(j)=temp
end if
next
next
sortNumericalArray = arrShort

end function

more info here:

ASP Sort Array Alphabetical

ASP Sort Numerical Array

Anonymous said...

This occurs beside isolation and speciation. Lack of awareness regarding health insurance for unemployed may push them in taking wrong decisions., vpn anyconnect domain. Traveling light is simply not an option when pets are involved. proxy unblocked

Anonymous said...

You’re able to place a backup of your former phone one on your new one., vpn protocols in windows. Poodles are like humans when it comes to their mental disposition. This is the time when we feel sleepy and that becomes unexpressable if we get a soft mattress to sleep over. open source vpn client windows. However we are also not saying that by paying a premium you are getting anymore. linux router firewall vpn

Anonymous said...

One or a few of them has stronger attraction than the others., change my internet ip. What's the moral of this story? You don’t have to write them down with your own handwriting on the board, but type and prints things out. ubuntu ipsec. A person suffering from anxiety and or depression may suffer from insomnia and find it difficult to fall asleep when he goes to bed at night or may wake during night or very early morning and find it difficult to fall asleep again. vpn broadband router

Anonymous said...

You can get ample of 25th anniversary gifts available online., crash server. Erectile dysfunction, or male impotence, is a medical condition that can affect individuals of all ages given the various factors that may lead to it. It is an ideal residential destination due to its central location and friendly community. connection enumerate network vbnet. The employer has influence on the selection process, but the agency handles the rest. wtw6600s top load washer

Anonymous said...

The reason behind this is the fact that merely providing a solution is not always enough for a business. rfc 2401. For example, the playground equipment manufacturer may include a main structure, a swing set, a climbing wall, a slide, monkey bars, a picnic table, sandbox, a ladder and/or the like. rc gas remote

Anonymous said...

Lack of maintenance will cost more due to higher costs associated with repairs or replacements to be made later. vpn 4.65. However, this phenomenon hadn’t been found in the female respondents. pes6 server

Anonymous said...

So in this article we will discuss some of the new ideas and techniques that raise the new technology of hormone replacement. Use these geocoordinates with a mapping program to establish the distance among any two internet sites, pinpoint customer places, or discover the closest to some customer., ilo remote control codes. The business gets boosted up with the presence on the web; a roar in online business affects sales and promotes the products in a new dimension. iif query access

Anonymous said...

Speak openly about building trust., privacy fances. Today the business of data center colocation is a huge industry in itself. A qualified therapist will teach you how to use your mind so that you can begin attracting what you want into your life. girl in white socks. This can cause serious problems including excessive scarring, infection, disfigurement in the forehead area and hair growing in the wrong direction. dungeons and dragons online private

Anonymous said...

The dermoid cyst may be available at birth. downtown los angeles virtual office services.com

Anonymous said...

If you want to grow your knowledge only keep visiting this
web site and be updated with the most up-to-date news update posted here.


Here is my homepage ... registry cleaner
My webpage: microsoft registry cleaner

Anonymous said...

buy generic valium online do generic valium pills look like - 10mg valium grasscity

Anonymous said...

I was wondering if you ever thought of changing the page layout
of your website? Its very well written; I love what youve got
to say. But maybe you could a little more in the way of content so people
could connect with it better. Youve got an awful lot of text for only having 1
or 2 images. Maybe you could space it out better?


Also visit my web site buy virility ex

Anonymous said...

It's very straightforward to find out any topic on net as compared to books, as I found this piece of writing at this web page.

Look into my weblog: buy genf20

Anonymous said...

Heya i'm for the primary time here. I found this board and I to find It truly useful & it helped me out a lot. I hope to present one thing back and aid others such as you aided me.

my website :: augmentation breast

Anonymous said...

This is my first time pay a quick visit at here and i am actually happy to read
all at alone place.

Take a look at my website buy xtreme no

Anonymous said...

Very quickly this website will be famous amid all blogging
and site-building people, due to it's pleasant articles

Also visit my web site; buy alta white

Anonymous said...

http://www.achildsplace.org/banners/tramadolonline/#6943 cheap tramadol - buy tramadol180

Anonymous said...

where to buy misoprostol in singapore - buy misoprostol cytotec online - buy cytotec online philippines

Anonymous said...

hey there and thank you for your information – I have certainly picked up anything new from right here.
I did however expertise a few technical issues using this
website, since I experienced to reload the website lots of times previous to I could get it to load correctly.
I had been wondering if your hosting is OK? Not that I'm complaining, but slow loading instances times will often affect your placement in google and can damage your high quality score if ads and marketing with Adwords. Anyway I'm adding this RSS to my email and could look out for much more of your respective exciting content.
Make sure you update this again very soon.

Here is my page: virility ex side effects

Anonymous said...

If you are going for most excellent contents like myself, only go to see
this web site all the time since it offers feature contents, thanks

Here is my homepage; provillus for women

Anonymous said...

buy tramadol overnight cod buy tramadolcheap no prescription - buy tramadol saturday delivery

Anonymous said...

My wife would probably think that buying a $500
handbag is important to her. And if is is, indeed, worth all the attention, then you may be wondering why it is worthy of such
attention. Other amazing results that have been proven from using this product
also include:.

Look into my web-site: buy vigrx plus

Anonymous said...

Can I submit your submit to my wordpress weblog? I will add a back-link to your forum.
That’s one really great post.

My website :: tips to get pregnant

Anonymous said...

Thank you for every other fantastic post. Where else may anybody get
that kind of info in such an ideal way of writing?

I've a presentation next week, and I'm at the search for such info.


Review my web blog; phen375

Anonymous said...

I have learn a few just right stuff here. Definitely value bookmarking for revisiting.
I surprise how so much effort you put to create this kind of magnificent informative site.


my blog; hoodi Gordonii

Anonymous said...

buy ambien us buy ambien walgreens - ambien to order online

Anonymous said...

each time i used to read smaller posts that as well clear their
motive, and that is also happening with this article which I am
reading now.

Feel free to visit my homepage: acaiberryselect.herbalcurenow.com

Anonymous said...

This reduction strategy effectively buys you some more time to repay your debt will only hurt your credit score improvement today.

Employing a consumer credit counseling compensated.

Once you are enrolled with a credit score improvement today.

A professional, highly trained bad credit installment loans
worker will be able to eliminate atleast 50% of your unsecured debt.


Here is my homepage :: bad credit finance

Anonymous said...

Excellent article. I'm experiencing many of these issues as well..

my homepage; triactol

Anonymous said...

Auto Insurance 52601 covers expenses that are related to it.
auto insurance 52601 discounts are available for most cities
in the country, particularly state regulators, who can do a great deal of individuals
contemplates when they're preparing to take a short inventory of your financial picture. Fuel economy 64 2mpgCO2 emissions 115g/km. The majority of injuries claimed from auto accidents are soft tissue injuries such as whiplash, sore neck or back.

Feel free to surf to my site - Car insurance

Anonymous said...

Paired with her favorite candy or popcorn treat, a collection of poetry.
With this women feel that hard attraction, blowing up girls realities,
and acting recklessly and dominantly. Humor is something that
a how to get a girlfriend lot of temptation. Another one is when you can objectively and
calmly consider what happened and what went wrong. If she
hits back, it's great and it should be in your company. Your spouse is trying to seduce a woman it comes out comical. It may not be shared by her.

Look into my page ... how get a girlfriend

Anonymous said...

Your current ωrіte-up οffeгs vеrifiеd helpful to me.
It’s rеally useful and yοu're obviously really knowledgeable in this region. You possess opened up my personal face for you to varying views on this matter along with interesting and strong written content.

Feel free to surf to my page ... buy ambien online

Anonymous said...

Yes even if your ways to attract women take her
phone with her where ever she goes. It all depends on how
you could ever find her. The truth is that a woman who
does not want to face the true facts honestly and sincerely.
The" new" Alpha and the ways of attracting women? No, I'm talking about. The bottom line is this: Attractive men who are successfully using alpha male body language. You go from one website to the next girl.

Anonymous said...

But I can tell. On some level, you need to rebuild and repair the
relationship with her again will change their life and every problem will disappear.
What's the question openerYou are going to assume that you want to get your ex how to attract younger women adored to score better points.

my web-site - how to attract women tips