Dynamically creating object names

  • Thread starter Thread starter RSH
  • Start date Start date
R

RSH

How do I go about creating an object name in a loop?

I have a class named objSample


Dim j As Integer

For j = 1 To 10

Dim inpFile As System.Web.UI.HtmlControls.HtmlInputFile =
FindControl(("UploadedFile" & j))

Dim "obj" & j as new objSample

("obj" & j).Prop1 = "Test1"

("obj" & j).Prop2 = "Test2"

Next



Am I going about this wrong? I have a situation where I need to iterate
through a series of objects that relate to form fields.

Thank for any help!

Ron
 
Hi,
How do I go about creating an object name in a loop?

I have a class named objSample


Dim j As Integer

For j = 1 To 10

Dim inpFile As System.Web.UI.HtmlControls.HtmlInputFile =
FindControl(("UploadedFile" & j))

Dim "obj" & j as new objSample

("obj" & j).Prop1 = "Test1"

("obj" & j).Prop2 = "Test2"

Next



Am I going about this wrong? I have a situation where I need to iterate
through a series of objects that relate to form fields.

Thank for any help!

Ron

That's exactly what arrays are for.

Create an array with 10 cells, of type objSample. Then in your loop,
populate each cell with a new objSample. You can then access the objects
through the array.

HTH,
Laurent
 
Back
Top