Below is the piece of code for sorting two dimensional array in vbscript. Try to execute it & should there be any concern, please let me know.
Cheers,
AB
Cheers,
AB
Code:
Dim Myarr(2,2)
Myarr(0,0) = 0
Myarr(0,1) = 6
Myarr(0,2) = 5
Myarr(1,0) = 1
Myarr(1,1) = 4
Myarr(1,2) = 3
Myarr(2,0) = 2
Myarr(2,1) = 8
Myarr(2,2) = 7
Call sortArray()
Function sortArray()
For row = 0 to UBound(Myarr, 1)
For col = 0 To UBound(Myarr, 2)
While Not (setRightDimension(row, col, Myarr(row, col)))
setRightDimension row, col, Myarr(row, col)
Wend
Next
Next
Msgbox "Sorting Completed!!!"
For i = 0 to UBound(Myarr, 1)
For j = 0 To UBound(Myarr, 2)
Print Myarr(i, j)
Next
Next
End Function
Function setRightDimension(ByVal rowNum, ByVal colNum, ByVal value1)
Dim originalColNumber:originalColNumber = colNum
Dim correctRow:correctRow = rowNum
Dim correctCol:correctCol = colNum
For rowNumber = rowNum to UBound(Myarr, 1)
For colNumber = colNum To UBound(Myarr, 2) Step 1
If value1 > Myarr(rowNumber, colNumber) Then
correctRow = rowNumber
correctCol = colNumber
End If
Next
If colNumber = UBound(Myarr, 2) + 1 Then
colNum = 0
End If
Next
If rowNum <> correctRow or originalColNumber <> correctCol Then
swap rowNum, originalColNumber, correctRow, correctCol
setRightDimension = False
Else
setRightDimension = True
End If
End Function
Function swap(ByVal oldRow, ByVal oldCol, ByVal newRow, ByVal newCol)
Dim temp:temp = Myarr(oldRow, oldCol)
Myarr(oldRow, oldCol) = Myarr(newRow, newCol)
Myarr(newRow, newCol) = temp
End Function
