To be honnest, Command or Method (yes it is a Method) I only want to achieve something and I do not care about the “quality” of a Language instruction.
In fact, I fall into a trap and had hard time to achieve my goal. TextArea1.AddText was not the command to use since… it Add Text (Append as we say earlier) after the Selected Text (so it deselect the text and append my text…). I had to code it differently:
// Get the selection
TA.Copy
// And replace it with:
TA.SelectedText = "<b>"
TA.Paste
TA.AddText ".</b><br>"
TA is my TextArea. Now I am happy.
BTW: Ian Kennedy wrote
“that was my point.”
and that was also my point !
Usually, a Paste, simply… paste the Clipboard contents and that is why I was stoned
(no pot involved here)
@Ian_Kennedy is correct. Because AddText and Paste do not return Strings/Text, Xojo does not know what to do here.
It looks to the Compiler as if you want to run 3 statements chained together with a +. You know that’s not possible.
If those Methods would return Strings, the Compiler could chain those 3 Strings together (still not knowing what to do with the resulting string)
Please forgive my very very old terminology. Just for those interested I’m harking back to VB days. A command was something you ran and didn’t return anything. Internally, in both VB and Xojo, they are “Sub” method, as opposed to a method that returned a result. Internally represented as a “Function” method. Sometimes it is hard to shake ones early days.
This will insert <b> by replacing the currently selected text, then insert the pasted text right after the <b> and finally add .</b><br> at the end of the TextArea.Text.
That was the goal. “My title” is at the end of the text. Now that I write this, I understand it can be… weird ! A title usually is at the top, not the text bottom as here. I think I will change that in case I come back in some months and react like you did minutes ago.
You are correct, it was positive. Since my memory is… working when it want, I am quite sure to forget why I coded that way as soon as a < 3 months old baby.
I try to avoid negative (even if sometimes…), I prefer constructive
For future reference. If you want to insert Clipboard Text at the current position even if it’s not at the end of the Text, you could do the following:
Var ClipText As New Clipboard
If ClipText.TextAvailable Then
Var s As String = ClipText.Text
ClipText.Text = "<b>" + s + ".</b><b>"
ClipText.Close
Me.Paste
End If