Dynamically creating object names

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
 
L

Laurent Bugnion

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
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,085
Latest member
cryptooseoagencies

Latest Threads

Top