whiwex
asked on
How to set a textbox as a object in vb6
How do you set a textbox as a object in VB6.
I want to be able do a loop that fills text boxes on a form.
Something like this:
Dim Tbox as object
BoxNum=2
Box="text"
while BoxNum < 20
set Tbox=Box & BoxNum
Tbox.value= BoxNum
BoxNum =BoxNum+1
wend
My problem is I don't know how to assing a object as a textbox or if that is what I should be doing.
I want to be able do a loop that fills text boxes on a form.
Something like this:
Dim Tbox as object
BoxNum=2
Box="text"
while BoxNum < 20
set Tbox=Box & BoxNum
Tbox.value= BoxNum
BoxNum =BoxNum+1
wend
My problem is I don't know how to assing a object as a textbox or if that is what I should be doing.
or even better.. use a control array, then you can use..
MyTextBoxName(BoxNum) = BoxNum
MyTextBoxName(BoxNum) = BoxNum
Actually, VB uses .Text instead of .Value as the propertie that stores its value. Access uses .Value.
Dim Tbox As TextBox
For Each Tbox In Form1
Tbox.Text = "Hello"
Next
For Each Tbox In Form1
Tbox.Text = "Hello"
Next
Dim Tbox
For Each Tbox In Form1
If TypeOf Tbox Is TextBox Then Tbox.Text = "Hello"
Next
For Each Tbox In Form1
If TypeOf Tbox Is TextBox Then Tbox.Text = "Hello"
Next
ASKER
No matter what I try I get errors.
Is your form's name Form1 ?
ASKER
I get Type mismatch with what ever I try to set the TBox to
Are you using VB6 ?
************************** ********** ********** ********** ********
Make a new Project. Add three Textboxes to Form1 (Text1 Text2 Text3).
Dim Tbox
For Each Tbox In Form1
If TypeOf Tbox Is TextBox Then Tbox.Text = "Hello"
Next
************************** ********** ********** ********** ********
**************************
Make a new Project. Add three Textboxes to Form1 (Text1 Text2 Text3).
Dim Tbox
For Each Tbox In Form1
If TypeOf Tbox Is TextBox Then Tbox.Text = "Hello"
Next
**************************
ASKER
elmar
i can do this.
What I want to be able to fill certain text boxes using a variable. Like
textboxX = something
textboxX+1 = something
thanks
i can do this.
What I want to be able to fill certain text boxes using a variable. Like
textboxX = something
textboxX+1 = something
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also note that it is case sensitive unless you include "option compare text" at the top of your form code
Add three Textboxes to Form1 (Text1 Text2 Text3).
Private Sub Form_Load()
textboxX 1, "something 1"
textboxX 2, "something 2"
End Sub
Sub textboxX(ByVal z As String, ByVal myText As String)
Dim Tbox
For Each Tbox In Form1
If TypeOf Tbox Is TextBox Then
If Tbox.Name = "Text" & z Then Tbox.Text = myText
End If
Next
End Sub
Private Sub Form_Load()
textboxX 1, "something 1"
textboxX 2, "something 2"
End Sub
Sub textboxX(ByVal z As String, ByVal myText As String)
Dim Tbox
For Each Tbox In Form1
If TypeOf Tbox Is TextBox Then
If Tbox.Name = "Text" & z Then Tbox.Text = myText
End If
Next
End Sub
Add 20 Textboxes to Form1 (Text1 Text2 Text3... ).
Private Sub Form_Load()
While BoxNum < 20
BoxNum = BoxNum + 1
textboxX BoxNum, "something " & BoxNum
Wend
End Sub
Sub textboxX(ByVal z As String, ByVal myText As String)
Dim Tbox
For Each Tbox In Form1
If TypeOf Tbox Is TextBox Then
If Tbox.Name = "Text" & z Then Tbox.Text = myText
End If
Next
End Sub
Private Sub Form_Load()
While BoxNum < 20
BoxNum = BoxNum + 1
textboxX BoxNum, "something " & BoxNum
Wend
End Sub
Sub textboxX(ByVal z As String, ByVal myText As String)
Dim Tbox
For Each Tbox In Form1
If TypeOf Tbox Is TextBox Then
If Tbox.Name = "Text" & z Then Tbox.Text = myText
End If
Next
End Sub
>Tbox.value= BoxNum
You should also be able to accomplish this with...
Me("text" & BoxNum).Value = BoxNum