By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

Replace Selected Text

P: n/a
jvb
Can anyone tell me why this isn't working in VB.NET 2003? And no, the
problem lies between the keyboard and the back of the chair is not a
valid answer!!!!

Me.TextBox1.SelectionStart = 0
Me.TextBox1.SelectionLength = 3
Me.TextBox1.SelectedText = "MOO"

Thanks

Feb 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I do not know why your code is not working:

Does the textbox have 3 characters in the textbox
Is the textbox readonly or locked
Is the textbox databound
Do you receive an exception
What does "isn't working" mean

may I suggest:

try
dim sTemp as string = ctype(Me.TextBox1.Text,string)

if stemp.length > 3 then
me.textbox1.text = string.format("{0}{1}","MOO",sTemp.Substring(3))
else
me.textbox1.text = string.format("{0}{1}","PEBKAC #1",sTemp)
end if

catch ex as exception
msgbox string.format("PEBKAC #2{0}{1}",vbcrlf, ex.tostring)
end try
"jvb" <go*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Can anyone tell me why this isn't working in VB.NET 2003? And no, the
problem lies between the keyboard and the back of the chair is not a
valid answer!!!!

Me.TextBox1.SelectionStart = 0
Me.TextBox1.SelectionLength = 3
Me.TextBox1.SelectedText = "MOO"

Thanks

Feb 16 '06 #2

P: n/a
jvb
Sorry for being so vague...When i execute the code above, it replaces
the selected text with an empty string. I will give your suggestion a
try. I am trying to get it to replace the selected text in the textbox
with a new value...a find/replace function.

Feb 16 '06 #3

P: n/a
"jvb" <go*****@gmail.com> schrieb
Can anyone tell me why this isn't working in VB.NET 2003? And no,
the problem lies between the keyboard and the back of the chair is
not a valid answer!!!!

Me.TextBox1.SelectionStart = 0
Me.TextBox1.SelectionLength = 3
Me.TextBox1.SelectedText = "MOO"


Here it works. Where do you execute this?
Armin

Feb 16 '06 #4

P: n/a
jvb
This code was excuted from the parent form (to test) as well as from
the find/replace form.

This is the solution i had to implement...

Dim HoldIndex As Int32

HoldIndex =
Me.TextBoxToEdit.Text.IndexOf(Me.cboFind.Text)

Me.TextBoxToEdit.Text =
Me.TextBoxToEdit.Text.Remove(HoldIndex, Len(Me.cboFind.Text))
Me.TextBoxToEdit.Text =
Me.TextBoxToEdit.Text.Insert(HoldIndex, cboReplace.Text)

Thanks for all your help!

JVB

Feb 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.