Home All Groups Group Topic Archive Search About

Replace Selected Text

Author
16 Feb 2006 8:49 PM
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

Author
16 Feb 2006 9:25 PM
Armin Zingler
"jvb" <gome***@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
Author
17 Feb 2006 3:24 PM
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
Author
16 Feb 2006 9:34 PM
AMDRIT
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


Show quoteHide quote
"jvb" <gome***@gmail.com> wrote in message
news:1140122990.846619.265580@z14g2000cwz.googlegroups.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
>
Author
16 Feb 2006 10:04 PM
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.