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!
|
You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
FREE! Go There Now!
|
|
|
|
Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right."
FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages.
FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
FREE! Go There Now!
|
|
|
|
Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing.
FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications.
FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
FREE! Go There Now!
|
|
|
|
Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise.
FREE! Go There Now!
|
|
|
|
The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable.
FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools!
|
|