Anders Franzen shares an easy way to sort a one dimensional array in this code sniplet.BR>
</PRE><PRE><%
<B>'**** March 2001 ****
'Author: Anders Franzen
'anders.franzen@banqit.com
'
'A easy way to sort a one dimensional array
'I use it a lot
'********************
</B>
Option Explicit
Function SelectionSort(TempArray, SortOrder)
Dim MaxVal, MaxIndex, i, x
<B>' Step through the elements in the array starting with the last element.
</B>For i = UBound(TempArray) To 0 Step -1
<B> ' Set MaxVal to the element in the array and save the
' index of this element as MaxIndex.
</B> MaxVal = TempArray(i)
MaxIndex = i
<B> ' Check the selected sortorder of the array
' "<" for DESC and ">" for ASC
</B> If SortOrder = "<" Then
<B> ' Loop through the remaining elements to see if any is
' larger than MaxVal. If it is then set this element
' to be the new MaxVal.
</B> For x = 0 To i
If TempArray(x) < MaxVal Then
MaxVal = TempArray(x)
MaxIndex = x
End If
Next
Else
For x = 0 To i
If TempArray(x) > MaxVal Then
MaxVal = TempArray(x)
MaxIndex = x
End If
Next
End If
If MaxIndex < i Then
TempArray(MaxIndex) = TempArray(i)
TempArray(i) = MaxVal
End If
Next
SelectionSort = TempArray
End Function
Sub SortMyArray()
Dim TheArray, i
<B>'Create the array
</B>TheArray = Array("Gambia", "Sweden", "France", "Denmark", "Estonia",
"Egypt", "USA", "Finland", "Canada", "Mexico")
<B>'You can insert any one dimensional array here
</B>TheArray = SelectionSort(TheArray, ">") 'Use ">" for Ascending and "<" for Descending
For i = 0 To UBound(TheArray)
Response.Write(TheArray(i) & "<br>")
Next
End Sub
<B>'Use like this
</B>Call SortMyArray()
%></PRE>
|
DISCLAIMER:
The content provided in this article is not warranted or guaranteed by Developer Shed, Inc.
The content provided is intended for entertainment and/or educational purposes in order to
introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent
upon the reader to employ real-world tactics for security and implementation of best practices.
We are not liable for any negative consequences that may result from implementing any information
covered in our articles or tutorials. If this is a hardware review, it is not recommended to open
and/or modify your hardware.
|
More ASP Code Articles More By Anders.Franzen
developerWorks - FREE Tools!
|
Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development
FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications.
FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset.
FREE! Go There Now!
|
|
|
|
Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server.
FREE! Go There Now!
|
|
|
|
Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available.
FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered!
FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
FREE! Go There Now!
|
|
|
|
With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential.
FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools!
|
|