Replace Selected Text

  • Thread starter Thread starter jvb
  • Start date Start date
J

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
 
jvb said:
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
 
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
 
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.
 
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
 
Back
Top