Represent a textbox.name with a string

bob.walker

Member
Joined
May 17, 2005
Messages
18
Programming Experience
3-5
I have a textbox "TB1" that I want to fill with "This Stuff"

x = 1
str = "TB"+x.tostring

?? str.text ?? = "This Stuff"

what do I use to show "str" is a control name?
 
Last edited:
found a way myself

Dim strg As String

Dim i As Integer

For i = 1 To 3 Step 1

strg =
"textbox" + i.ToString

Obj(
Me, strg).Text =
"Larry" + i.ToString

Next

 
Sorry, I guess you needed the function too?

Private
Function Obj(ByVal sender As System.Object, ByVal cControlName As String) As Control
Dim i As Integer

For i = 0 To sender.controls.Count - 1

If sender.Controls(i).Name.toUpper = cControlName.ToUpper Then

Return sender.Controls(i)

End If

Next

End
Function

 
Another way is to initialize in beginning

Private oP1_TAB(4) As TextBox

then in load method

oP1_TAB(0) = textbox_Zero
oP1_TAB(1) = textbox_One
oP1_TAB(2) = textbox_Two
oP1_TAB(3) = textbox_Three

For x = 0 To 3

If oCont.Rows(x).IsNull("docu") Then
oP1_TAB(x).Text = Nothing
Else
oP1_TAB(x).Text = oCont.Rows(x).Item("docu")
oP1_TAB(x).Tag = oCont.Rows(x).Item("rownumber")
End If

Next

then in save method

For x = 0 To 3

sStmt = "update Emppage5 set "
If oP1_TAB(x).TextLength < 1 Then
sStmt += "docu = null "
Else
sStmt += " docu = '" + oP5_TB(x).Text + "' "
End If
sStmt += "where rownumber = " + CType(oP5_TB(x).Tag, String)

SQLEXE(sStmt, oConn)

** in the tag when loading I put the rownumber
 
Back
Top