Insert text into a text box.[RESOLVED]
Hello,
I am trying to figure out how to insert a line of text into a text box where the cursor is located.
Insert "Hello World" into a textbox.
Text Box = "This is so|me text"
| = Cursor
Inserted Text Box = "This is soHello Worldme text"
My first idea is to store the text before the cursor into a variable and the text after the cursor into another variable.
To insert the text I just:
VB Code:
textbox.text = strTextBeforeCursor & strTextInsert & strTextAfterCursor
Anyone else think there is an easier idea?
Thanks for your input! :cool:
Re: Insert text into a text box.
Try this very simple approach first:
VB Code:
Private Sub Command1_Click()
Dim pos%
pos = Text1.SelStart 'get current cursor position
Text1.Text = Left(Text1.Text, pos) & "_ABC_" & Mid(Text1.Text, pos + 1)
End Sub
Re: Insert text into a text box.
Why bother finding where the Cursor is, when SelStart is where it is anyway?
VB Code:
TextBox.SelText = "Hello World"
Phreak
Re: Insert text into a text box.
Why bother? Because I wanted to ... ;) But your sample will do it as well. :thumb:
Re: Insert text into a text box.
I realise I sounded a bit annoyed in my previous post. My bad :)
We're all happy here..
Phreak
Re: Insert text into a text box.
Quote:
Originally Posted by «°°phReAk°°»
... We're all happy here ...
Yea, so far ... :)
Re: Insert text into a text box.[RESOLVED]
I am all smiles here!
:) :cool: :lol: :p :wave: ;) :bigyello: :thumb: :D :afrog: :mike: :duck:
Thanks for taking the time to answer a stupid question ;)
(so easy)
Re: Insert text into a text box.[RESOLVED]
There aint stupid questions ...
You're welcome. :wave: