For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > November 2005 > Highlightng Text from anywhere









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Highlightng Text from anywhere
David Bland

2005-11-25, 6:55 pm

Hi

What I want to do is to be able to pass a text box name from anywhere and
highlight the text. I thought this would work, but it does not.

HighlightText txtTextBox.Name

Private Sub HighlightText(txtBoxIn As TextBox)
With txtBoxIn
.SelStart = 0
.SelLength = Len(txtBoxIn.Text)
End With
End Sub

I get a Type Mismatch on the .Name any ideas?
Rick Rothstein [MVP - Visual Basic]

2005-11-25, 6:55 pm

> What I want to do is to be able to pass a text box name from
anywhere and
> highlight the text. I thought this would work, but it does not.
>
> HighlightText txtTextBox.Name
>
> Private Sub HighlightText(txtBoxIn As TextBox)
> With txtBoxIn
> .SelStart = 0
> .SelLength = Len(txtBoxIn.Text)
> End With
> End Sub
>
> I get a Type Mismatch on the .Name any ideas?


The Name of a control is a String... your function is expecting the
control itself. Use this to call the function (it passes the control
itself into the function)...

HighlightText txtTextBox

Rick


Joe O

2005-11-25, 6:55 pm

Remove .Name
txtTextBox alone should do it

"David Bland" <DavidBland@discussions.microsoft.com> wrote in message
news:65753CE4-9308-42E7-955C-536B9D054F51@microsoft.com...
> Hi
>
> What I want to do is to be able to pass a text box name from anywhere and
> highlight the text. I thought this would work, but it does not.
>
> HighlightText txtTextBox.Name
>
> Private Sub HighlightText(txtBoxIn As TextBox)
> With txtBoxIn
> .SelStart = 0
> .SelLength = Len(txtBoxIn.Text)
> End With
> End Sub
>
> I get a Type Mismatch on the .Name any ideas?



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com