Hi AndreK,
I tried your code but it didn't make my array elements in ascending order.
I wrote a small function to do this. You have to pass the string you need to make in ascening order and function will return a array of elements ordered by ASC. If you are worrying about the CASE of your characters please modify the relavant line.
If you don't have SQL Server use Access or any other ...
[u]Function</u>
Public Function String_Order(ByVal strMyString As String) As Variant
Dim MyArray() As String
Dim intLoop As Integer
Dim intVal As Integer
Dim rsPrimary As New ADODB.Recordset
On Error GoTo ERROR_HANDLER
cnn.Execute "CREATE TABLE #values(value int)"
For intLoop = 0 To (Len(strMyString) - 1)
ReDim Preserve MyArray(intLoop)
intVal = Asc(UCase(Mid(strMyString, intLoop + 1, 1)))
cnn.Execute "INSERT INTO #values VALUES(" & intVal & ")"
Next
rsPrimary.Open "SELECT value FROM #values ORDER BY value", cnn
intLoop = 0
Do While Not rsPrimary.EOF
MyArray(intLoop) = Chr(CLng(rsPrimary!Value))
rsPrimary.MoveNext
intLoop = intLoop + 1
Loop
String_Order = MyArray()
Exit Function
ERROR_HANDLER:
cnn.Execute "DROP TABLE #values"
Resume
End Function
Private Sub Form_Load()
Set cnn = New ADODB.Connection
cnn.Open "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=serverdatabase;Data Source=(local)"
End Sub
[u]Testing the Function</u>
Private Sub Command1_Click()
Dim arrString As Variant
Dim str As String
Dim i As Integer
arrString = String_Order("Nalaka")
For i = 0 To UBound(arrString)
str = str & arrString(i)
Next i
MsgBox str
End Sub
Please post if you need more info regarding this.
nalaka hewage
|