TextArea1.Paste cannot be added into a String (concatenated)

I wanted to do:

TA.AddText "<b>" + TA.Paste + ".</b><br>"

in a Desktop project, but it is not possible.

Apparently, I have to use three lines:

TA.AddText "<b>"
TA.AddText ".</b><br>"

NB: The code above was not tested… so I may have to do that differently…

Am I the only one to fall into that trap ?

TA.Paste is a command, not a method that returns a string, thus you can’t use it as a string.

You can, however, get the contents of the clipboard (assuming desktop applications):

Var oClip as New Clipboard
if oClip.TextAvailable then
   TA.AddText "<b>" + oClip.Text + ".</b><br>"
end if

That’s not correct. Paste is a Method of the TextArea:

Pastes the styled or unstyled text on the Clipboard into the editing area at the insertion point, adding the text to the existing text.

And AddText is another Method:

Adds the passed text to the current Text. Call AddText rather than using the + operator to add text to existing text.

Yes, you are perfectly correct, but it doesn’t return a string, that was my point.

Yes, not sure why you are pointing this out, but it is correct. I only showed how the OP could do what is requested. In a different way.

1 Like

Thank you for your answers.

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

// And replace it with:
TA.SelectedText = "<b>"
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 ! :wink:

Usually, a Paste, simply… paste the Clipboard contents and that is why I was stoned :wink:
(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) :wink:

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.

1 Like

That is just because TextArea1.Paste behavior is different than ClipBoard1.Paste…

But I was awaiting the same behavior.

NB: the documentation defines that behavior…

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.

If that was the goal :slight_smile:

We are always happy when someone with more knowledge helps.
I don’t even know the difference between commands, methods, statements, … :man_shrugging: :blush:

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.


1 Like

I don’t know if that was meant in a positive way, but that’s how I understand it. :wink:

I’m certainly not claiming any knowledge, just excusing my mid-20th century slip :smiley:

1 Like

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. :slight_smile:

I try to avoid negative (even if sometimes…), I prefer constructive :wink:

1 Like

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>"
End If

Thanks. Since I had to stay away from the forum for a few months for health reasons, I was concerned that my “sudden” comment might be misconstrued.

I know that you help where you can and I try to follow your example as often as I can.

Thank you Emile :+1:

Sad news; I am sorry. I wish your health to come back asap.



DesktopTextArea.Paste did not return something so + without a string should raise an compile time error.

I’m reading Ian’s sentence as being
“Paste is a command, not a-method-that-returns-a-string”, thus not implying it’s not a method at all :wink:

Comments in code are made for that :wink:

1 Like