Dynamically creating object names

Discussion in 'ASP .Net' started by RSH, Sep 11, 2006.

  1. RSH

    RSH Guest

    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
     
    RSH, Sep 11, 2006
    #1
    1. Advertising

  2. Hi,

    RSH wrote:
    > 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
    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, Sep 11, 2006
    #2
    1. Advertising

  3. RSH

    RSH Guest

    PERFECT!

    Thanks!

    Ron


    "Laurent Bugnion" <> wrote in message
    news:%...
    > Hi,
    >
    > RSH wrote:
    >> 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
    > --
    > Laurent Bugnion, GalaSoft
    > Software engineering: http://www.galasoft-LB.ch
    > PhotoAlbum: http://www.galasoft-LB.ch/pictures
    > Support children in Calcutta: http://www.calcutta-espoir.ch
     
    RSH, Sep 11, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paddy McCarthy
    Replies:
    3
    Views:
    715
    Anthony J Bybell
    Sep 24, 2004
  2. Bob
    Replies:
    1
    Views:
    385
    Lucas Tam
    Jul 30, 2004
  3. wanwan
    Replies:
    3
    Views:
    432
    Alex Martelli
    Oct 14, 2005
  4. Replies:
    2
    Views:
    524
    Chandra Kalle
    Apr 13, 2006
  5. Jess
    Replies:
    10
    Views:
    504
    James Kanze
    May 18, 2007
Loading...

Share This Page