|
-
Jan 9th, 2009, 08:47 AM
#1
Thread Starter
Lively Member
Same Event for Every Textbox!
Hello, i have 48 textbox between tabs and i want to do this
Code:
textbox.selstart = 0
textbox.sellength = len(trim(textbox))
in the got_focus event. I have to write this 48 times? it there a way to add this event for all textbox on load-time or something? thanks.
-
Jan 9th, 2009, 09:07 AM
#2
Re: Same Event for Every Textbox!
If you can convert all of your textboxes to Control Array (same Name but each will have unique Index) then you will be able to do something like this:
Code:
Private Sub Text1_GotFocus(Index As Integer)
Text1(Index).SelStart = 0
Text1(Index).SelLength = Len(Text1(Index).Text)
End Sub
-
Jan 9th, 2009, 09:12 AM
#3
Re: Same Event for Every Textbox!
 Originally Posted by CVDpr
Hello, i have 48 textbox between tabs and i want to do this
Code:
textbox.selstart = 0
textbox.sellength = len(trim(textbox))
in the got_focus event. I have to write this 48 times? it there a way to add this event for all textbox on load-time or something? thanks.
What do you mean by this? Also, I hope that these 48 TextBoxes are in a Control Array.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jan 9th, 2009, 09:27 AM
#4
Thread Starter
Lively Member
Re: Same Event for Every Textbox!
If all have the same name, then its gonna be difficult to remember what textbox is for and add the values to a storeprocedure.
txtResLowLimit
txtResHighlimit
txtMax
etc..
-
Jan 9th, 2009, 09:44 AM
#5
Re: Same Event for Every Textbox!
 Originally Posted by CVDpr
If all have the same name, then its gonna be difficult to remember what textbox is for and add the values to a storeprocedure.
Not really - you can write some name to a Tag property when you create new control - you do that anyway by assigning the Name property so instead you'd use Tag.
-
Jan 9th, 2009, 09:45 AM
#6
Re: Same Event for Every Textbox!
 Originally Posted by CVDpr
If all have the same name, then its gonna be difficult to remember what textbox is for
I agree which is why I never (well, almost never) use control arrays.
The one, and only, other alternative is to place your code in each individual textbox - all 48 one by each.
A method I find infinately preferable to using a control array.
-
Jan 9th, 2009, 10:04 AM
#7
Thread Starter
Lively Member
Re: Same Event for Every Textbox!
if i use the tag, how to msgbox the value of the textox that have the tag "low"?
msgbox Text1.Item(1), this work, but how to use the tagname "low" and not the index number?
-
Jan 9th, 2009, 10:10 AM
#8
Re: Same Event for Every Textbox!
If you use control array then you must provide control's Index:
Code:
MsgBox Text1(Index).Tag
-
Jan 9th, 2009, 10:35 AM
#9
Thread Starter
Lively Member
Re: Same Event for Every Textbox!
 Originally Posted by RhinoBull
If you use control array then you must provide control's Index:
Code:
MsgBox Text1(Index).Tag
but i want the textbox value not the tag value :-(
textbox1(1) has 125.00 and tag "low"
i want to msgbox the textbox.text that has the tag "low"
Last edited by CVDpr; Jan 9th, 2009 at 10:44 AM.
-
Jan 9th, 2009, 10:59 AM
#10
Re: Same Event for Every Textbox!
Then use the .Text property (Text1(1).Text)
-
Jan 9th, 2009, 11:06 AM
#11
Re: Same Event for Every Textbox!
 Originally Posted by CVDpr
i want to msgbox the textbox.text that has the tag "low"
Try this then:
Code:
Option Explicit
Private Sub Command1_Click()
Dim myText As String
myText = GetText("Text1", "low")
MsgBox myText
End Sub
Public Function GetText(myName As String, myTag As String) As String
Dim txt As Control, myText As String
For Each txt In Me.Controls
If TypeOf txt Is TextBox And LCase(txt.Name) = LCase(myName) Then
If LCase(txt.Tag) = LCase(myTag) Then
myText = txt.Text
Exit For
End If
End If
Next txt
GetText = myText
End Function
-
Jan 9th, 2009, 11:31 AM
#12
Re: Same Event for Every Textbox!
 Originally Posted by Hack
I agree which is why I never (well, almost never) use control arrays....
I'm rather shocked. Why not do this?
Code:
Option Explicit
Private Enum EmpName
EmpFirstName
EmpMI
EmpLastName
End Enum
Private Sub Form_Load()
txtName(EmpFirstName) = "marty"
End Sub
-
Jan 9th, 2009, 11:55 AM
#13
Re: Same Event for Every Textbox!
Not a bad idea, Marty.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|