# Solved: event/procedure in Visual Basic 6



## CVDpr (Feb 23, 2005)

Hey there, i have this in a textbox


```
Private Sub txtFcid_GotFocus()

   With txtFcid
           .SelStart = 0
            .SelLength = Len(txtFcid)
End With

End Sub
```
Can i include more than one textbox to share this event or i have to put this in every textbox?


----------



## Chicon (Jul 29, 2004)

There's an exemple of events sharing on the following link :
http://msdn.microsoft.com/en-us/library/4ac48519.aspx
Though the example concerns buttons, the same philosophy may be applied to textboxes.


----------



## CVDpr (Feb 23, 2005)

a think that doest not work in vb6


----------



## Chicon (Jul 29, 2004)

Just try this :
- Implements the following event handler in your coding 
(I've assumed you have 2 textboxes called TextBox1 and TextBox2) 

```
[SIZE=2]
Private Sub TextBoxesFocus( ByVal sender As Object, ByVal e As System.EventArgs ) _
     Handles TextBox1.GotFocus, TextBox2.GotFocus
     Dim tb As TextBox
     tb = CType(sender, TextBox)
     With tb
           .SelStart = 0
           .SelLength = Len(tb)
     End With
End Sub
[/SIZE]
```
- Set your events handlers in comments
- For each textbox, on the View menu, choose Code to open the Code Editor :
in the _GotFocus_ method declaration, replace the vent cluse by the following text
*Private Sub TextBoxesFocus( ByVal sender As Object, ByVal e As System.EventArgs ) Handles TextBox1.GotFocus, TextBox2.GotFocus*


----------



## Aftab (Oct 15, 2003)

I don't think VB6 allows event sharing, you could write 1 procedure to do what you want and then call that in the Gotfocus for each textbox.

i.e

private sub highlight(tb as textbox)

With tb
.SelStart = 0
.SelLength = Len(tb)
End With

End Sub


----------



## Chicon (Jul 29, 2004)

You're right, Aftab !

Hmm ! I messed with the VB version.


----------



## Aftab (Oct 15, 2003)

Now CVDpr should know how to do it in VB6 and VB.NET:up:


----------

