There is no such thing as. TextArea1.AppendTextFromCursor (strText)
But how do I insert text not at the end, append, but at the position of the cursor!?
TextArea1.SelLength = 10
The above code sets the caret to a certain position, if that is what you needed?
TextArea1.SelText = textToInsert
Ah, Richard. Well, well, well. Beat me to this one. Oh well, you win some, you loose some [strokes white cat]
They don’t call me “Quick-Fingers” for nothing!
[quote=151366:@Richard Summers]TextArea1.SelLength = 10
The above code sets the caret to a certain position, if that is what you needed?[/quote]
It’s strange!!
When you do other things all the bight ideas comes alive! It keeps happening to me!
Now, I thought of the solution while biking to the store…
It seems that AFK is the more productive part of the development…! Ha!
OK, yes. I get 10 as the integer and then insert text at this point. So, how do I insert at position 10…
I’ll look for that one.
No, SelStart it is. Not SelLength. (???)
[quote=151407:@Jakob Krabbe]It’s strange!!
When you do other things all the bight ideas comes alive! [/quote]
That’s why all good professionals have down-time planned in. It gives you a chance to unwind and get new energy as well as new ideas. If you are working long hours and it is hard then you are not efficient.
Where your text cursor is, that is .SelStart.
Note that this is different from your pointer cursor!
As you haven’t specified a selection length .SelLength is zero. So you can simply do
TextArea1.SelStart = textToInsert
And your text will be inserted where your cursor is.
If some text is selected then the selected text is replaced.
You can select some text by placing the cursor at the right end and specify how long the selection should be:
TextArea1.SelStart = 22
TextArea1.SelLength = 15
Text cursor vs. pointer cursor!
It’s difficult to write the question when you don’t even know the proper words!
Thank you!
[code]Sub insertChar(myVar as string)
'txtCopy.text = txtCopy.text + myVar
DIM intFirst as Int64 = txtCopy.SelStart
DIM intSecond as Int64 = LEN(txtCopy.text) - intFirst
DIM strFirst as string = LEFT( txtCopy.text, intFirst )
DIM strSecond as string = RIGHT( txtCopy.text, intSecond )
txtCopy.text = strFirst + myVar + strSecond
End Sub
[/code]
This works.
You get the idea.
But at this moment, you need to press “the pointer cursor to place the text cursor in position” again after the first time, the second time. To get the cursor in position. Or it will be zero. (0)
I shall try to solve this later, tomorrow.
Thank you for good advice!
Jakob,
try this - it is probably easier for you
Dim myString As String = Left(TextField1.text, 10)
myString = myString + "extra text goes here"
This will take the first 10 characters from TextField1, and append “extra text goes here” to the end.
If you then need to add the last characters back onto the string, just use the additional line of code"
myString = myString + Right(TextField1.text, 5)
This will then add the 5 right-most characters back onto the string.
There are many different ways of achieving this
Maybe I’m missing something, but it seems to me you guys are hitting the target, but missing the bullseye.
SelStart = The Insertion point
SelLength = How many characters are selected / highlighted
SelText = Get or Set the text represented by SelStart/SelLength
So to insert text at the insertion point
txtCopy.SelText = myVar
If you want to insert text at a specific point
txtCopy.SelStart = 10 // or wherever
txtCopy.SelText = myVar
To replace some text at some point
txtCopy.Text = "The quick brown fox"
txtCopy.SelStart = 4
txtCopy.SelLength = 5
txtCopy.SelText = "slow"
msgbox txtCopy.Text // "The slow brown fox"
[quote=151413:@Jakob Krabbe]Text cursor vs. pointer cursor!
It’s difficult to write the question when you don’t even know the proper words!
Thank you!
[code]Sub insertChar(myVar as string)
'txtCopy.text = txtCopy.text + myVar
DIM intFirst as Int64 = txtCopy.SelStart
DIM intSecond as Int64 = LEN(txtCopy.text) - intFirst
DIM strFirst as string = LEFT( txtCopy.text, intFirst )
DIM strSecond as string = RIGHT( txtCopy.text, intSecond )
txtCopy.text = strFirst + myVar + strSecond
End Sub
[/code]
This works.
You get the idea.
But at this moment, you need to press “the pointer cursor to place the text cursor in position” again after the first time, the second time. To get the cursor in position. Or it will be zero. (0)
I shall try to solve this later, tomorrow.
Thank you for good advice![/quote]
Jakob, this iscompletely unnecessary. Read again what I wrote.
He meant
TextArea1.SelText = textToInsert
Exactly as Tim says. Seems I’m turning into Charles
It works just like in any word processor.
If you paste text then what happens? The selected text gets replaced.
What if you have no text selected? Then basically you have a selected text with selection length zero.
In either case the text is inserted where your insertion point is.
Fellow hackers!
Excuse me for the slow conversation.
Your answers are all sort of wrong and it’s all my fault. I asked the wrong question. Then, what to expect!?
This thread ends up in another annoying thread (made by me):
https://forum.xojo.com/17941-no-sign-on-my-keyboard
The code solves the second line. When writing a text you can press the at-sign and the second will appear after the first one, in a row.
However, if the user, for some unknown reason, press the the cursor before the first character, then I think it will not work… But also, I’m the only user in this case and I can live with that!
[code]Sub insertChar(myVar as string)
IF txtCopy.SelStart <> 0 THEN intCursorPos = txtCopy.SelStart
DIM intFirst as Int64 = intCursorPos
DIM intSecond as Int64 = LEN(txtCopy.text) - intFirst
DIM myText as string = txtCopy.text
DIM strFirst as string = LEFT( myText, intFirst )
DIM strSecond as string = RIGHT( myText, intSecond )
txtCopy.text = strFirst + myVar + strSecond
intCursorPos = intCursorPos + 1
End Sub
[/code]
Been there, done that.
Just glad you got it sorted.
You’re still doing it wrong. That’s way more work than it should be. Use SelText like we told you. You’re forcing a complete reload of the field just to insert one character.
And this can get very slow when if/when there’s a lot of text involved.