Link to home
Start Free TrialLog in
Avatar of stromberg10
stromberg10

asked on

Insert variable at the cursor in an textbox

I've a function which inserts todays date in a textbox like this: textbox.Text = textbox.Text + date
As you can see the date gets written in the end of the textbox.

How it looks like now, if I insert the date:
"I was in Sweden. It was fun." + date

I wanna have it like this:
"I was in Sweden" + date + ". It was fun."

I've tested some with SelectStart and so on, but with no success.
Hopes you understand and are willing to help =)!
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you need to programmatically position the cursor before you insert the date then set the focus to the box and use the SelectionStart and SelectionLength properties:

        TextBox1.Focus()
        TextBox1.SelectionStart = 5
        TextBox1.SelectionLength = 0

~IM
Avatar of stromberg10
stromberg10

ASKER

I made it myself :D, but thanks for the help!

I did like this:
textBox.Text = textBox.Text.Insert(textBox.SelectionStart, Date.Now)