Hey everybody,
I hope that someone can help me with my problem:
I'm trying to built a function that can sort the letters within a string alphabetically.
I figured out how to do it in Excel, but I don't know how to get it done in IDEA Basic.
Option Explicit
Public Function sortieren(zelle) As String
Dim objAL As Object
Dim I As Integer
Set objAL = CreateObject("System.Collections.Arraylist")
With objAL
For I = 1 To Len(zelle.Text)
.Add (Mid(zelle.Text, I, 1))
Next
.Sort
sortieren = Join(.toArray, "")
End With
Set objAL = Nothing
End Function
Thanks a lot
Hi Stephan,
Here is an example using the internal IDEAScripting array and then sorting it. This array is for integers but it can be easily changed for strings. I have used the collections in the past but usually I stick with the internal array structure if I can.
Here is an example of a list of random number before being sorted:
and after:
Here is the code to generate the array and do the sort:
Hi Brian,
thanks for your message :-)
I played around with your script for a while but I don't seem to be able to get what I want.
Is there a way to build a user defined function which I can use in an added field of my table to get the following result: "Stephan" --> "aehnpSt"
This would be exactly the same what I managed to do in Excel.
Maybe you can help me out again
Hi Stephan,
Any chance you can give me an example of what you are trying to do, such as a before and after as I am not sure what you are looking for right now and I will try and help out once I understand exactly what are trying to accomplish.
Thanks
Brian
Hi Brian,
what I'm trying to do is adding a field to my existing table with the letters sorted alphabetically like here (Column 1 "Name1" exists in my table and Column 2 "Sortiert" will be added using the sorting function):
Thanks Stephan, I understand now. Is this part of a script as you can do this with a Custom Function as part of the equation editor so you don't actually need a script. The only problem with doing sorting is an A is not the same as an a, so your first item would probably be AGHSaccehhmnnoortu as capitals are sorted as lower than lower case (I think).
Brian
A custom function is exactly what I'm looking for :-) But it seems I'm not able to build it... Or is there a function which I haven't found yet?
Stephan
No, I will have to combine a few things. Let me get back to you with something.
Sounds great, thank you Brian :-)
Hi Stephan,
Try out this custom function. Just save it in your projects Custom Functions.ILB folder and the syntax to use it in the Equation editor is #SortChar(MY_FIELD). It seems to be giving me the same result as what you posted.
Brian
Hey Brian,
the function works great, thank you so much :-)
Stephan
Pages