Tricks with StringsField-a "cbadegf" === "abcdefg"
And also is there a way to attach fields without including the spaces. For example:
Field-a "My name " Field-b "is Don " Result "My name is Don"
From: Don Amaro Concepcion
Email: amaro@pi.net
Assuming that you will only have one occurrence of each character in the field you want to sort, and that you are only dealing with lower case letters (as it appears you are), the following code should do the trick:
Function SortField (Byval sIn As String) As String
Dim sTemp As String
Dim iChar As Integer
Dim sResult As String
sResult = ""
For iChar = Asc("a") To Asc("z")
sTemp = Chr$(iChar)
If InStr(sIn, sTemp) Then
sResult = sResult & sTemp
End If
Next iChar
SortField = sResult
End Function
As you can see it simply loops through all the characters we are interested in using their integer representations (ANSI codes). If the character appears in the source string then we append it to the destination string. Because we are iterating through the characters in order this has the effect of ordering them.
Your second question about attaching fields is also done quite simply. Visual Basic comes with three functions built in for trimming spaces from strings. RTrim will trim spaces for the right hand side of a string, LTrim will trim spaces form the left hand end of a string and Trim will trim spaces from both ends. So to concatenate your two strings as required you would simply use the following code:
sDestField = Trim$(a-field) & " " & Trim$(b-field)
You will notice that I have inserted a space in the middle so that the two fields will be separated by a single space. Visual Basic has a whole pile of String handling functions most of which are really rather good, and pretty quick as well, it's worth a tip-toe through the Help file to discover some of the more useful and less obvious ones.