Using Variable for Text Box Name

G

Guest

In vb.net I'm trying to loop through textboxes using variables. If I try the
following, I receive the error "Value of type string cannot be converted to
System.Windows.Forms.Textbox

dim theTextBox as textbox
dim strName as string
dim i as integer
strname = "txtclorderfield" & i & ".text"
thetextbox = strname < this is where the syntax error appears
 
G

Guest

I still can't access the text that is in the text box. I receive the
following error:Object reference not set to an instance of an object. Here's
what I have for code. The error occurs on the strvalue =

Thanx,
Mike

Dim i As Integer
Dim strValue As String
Dim strTextBox As String
strValue = FindControl("txtclorderfield" & (i + 1) & ".text", Me).ToString

Private Function FindControl(ByVal ControlName As String, ByVal
CurrentControl As Control) As Control
For Each ctr As Control In CurrentControl.Controls
If ctr.Name = ControlName Then
Return ctr
Else
ctr = FindControl(ControlName, ctr)
If Not ctr Is Nothing Then
Return ctr
End If
End If
Next
End Function
 
J

Josh Belden

Shouldn't this...

strValue = FindControl("txtclorderfield" & (i + 1) & ".text", Me).ToString

be...

strValue = FindControl("txtclorderfield" & (i + 1), Me).Text
 
G

Guest

I receive this error when trying that:
Object reference not set to an instance of an object.

Does it matter that I'm doing this from within a tab control?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top