123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home

Source Codes

Engineering Colleges

BE Students

Training  Reports (updated)

Seminar Reports (updated

Placement Papers (updated)

Forums

   Computer Science / IT

   Electronics

   Electrical

   Mechanical

   Chemical

   Civil

   CAT / MBA

   GMAT / Foreign MBA

Latest Jobs

Engineering Jobs / Technical Jobs

Management Jobs

Sitemap

About-Us

Terms of use

Displaying  Source Code(s)  
 

 
Sort arrays

--------------------------------------------------------------------------------

Description : Vbscript function that sorts an one-dimensional array of number either ascending or descending. This function sorts using the well known double for..next principle. Script gives an overview of passing parameters and especially passing arrays of numbers to a function.

'--------Begin Function----
Function fnSort(aSort, intAsc)
Dim intTempStore
Dim i, j
For i = 0 To UBound(aSort) - 1
For j = i To UBound(aSort)
'Sort Ascending
If intAsc = 1 Then
If aSort(i) > aSort(j) Then
intTempStore = aSort(i)
aSort(i) = aSort(j)
aSort(j) = intTempStore
End If 'i > j
'Sort Descending
Else
If aSort(i) < aSort(j) Then
intTempStore = aSort(i)
aSort(i) = aSort(j)
aSort(j) = intTempStore
End If 'i < j
End If 'intAsc = 1
Next 'j
Next 'i
fnSort = aSort
End Function 'fnSort
'-------------------------
Dim aUnSort(3), aSorted
aUnSort(0) = 4
aUnSort(1) = 2
aUnSort(2) = 6
aUnSort(3) = 20
'call the function
'second argument:
' * ascending sorted = 1
' * descending sorting = any other chara
' cter
aSorted = fnSort(aUnSort, 1)
Erase aUnSort
 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved copyright 123ENG