Results 1 to 6 of 6

Thread: want to set "Object variable name" dynamically ...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    fgh
    Posts
    332

    want to set "Object variable name" dynamically ...

    Hi techs

    dim country as string
    country="INDIA"
    dim country as new System.Collections.ArrayList()

    I need to give an object name dynamically...
    How can i set an objectname dynamically ... dynamic input will be in string format ....

    thankzzz
    Last edited by sureshvijayan; Oct 19th, 2007 at 03:47 AM.
    gh

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: want to set "Object variable name" dynamically ...

    I'm afraid you are confused. How can the user provide a variable name at run time when variable names don't exist at run time? Variable names are just identifiers so the developer can recognise what the variable is for. Once you compile your code those names cease to exist because the system doesn't need them.

    Not only that, variables are NOT object names. A variable is NOT an object. Look at this code:
    vb.net Code:
    1. Dim obj1 As New Object
    2. Dim obj2 As Object = obj1
    3. Dim obj3 As Object = obj2
    There are three variables (obj1, obj2 and obj3) and only one object, so what's the object's name? The answer is that it doesn't have a name. It's just an object referred to by three different variables. Now look at this:
    vb.net Code:
    1. Dim ctl1 As New Control
    2.  
    3. ctl1.Name = "A new control"
    4.  
    5. Dim ctl2 As Control = ctl1
    6. Dim ctl3 As Control = ctl2
    Now there are three variables named ctl1, ctl2 and ctl3, plus there's one Control object. This control does have a name because the Control class has a Name property. That property has no relationship whatsoever to the variables that may refer to the object.

    Now, hopefully I've demonstrated that what you've asked for makes no sense, so please explain what the intended functionality is and we can try to advise how to achieve it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    fgh
    Posts
    332

    Re: want to set "Object variable name" dynamically ...

    Quote Originally Posted by jmcilhinney
    I'm afraid you are confused. How can the user provide a variable name at run time when variable names don't exist at run time? Variable names are just identifiers so the developer can recognise what the variable is for. Once you compile your code those names cease to exist because the system doesn't need them.

    Not only that, variables are NOT object names. A variable is NOT an object. Look at this code:
    vb.net Code:
    1. Dim obj1 As New Object
    2. Dim obj2 As Object = obj1
    3. Dim obj3 As Object = obj2
    There are three variables (obj1, obj2 and obj3) and only one object, so what's the object's name? The answer is that it doesn't have a name. It's just an object referred to by three different variables. Now look at this:
    vb.net Code:
    1. Dim ctl1 As New Control
    2.  
    3. ctl1.Name = "A new control"
    4.  
    5. Dim ctl2 As Control = ctl1
    6. Dim ctl3 As Control = ctl2
    Now there are three variables named ctl1, ctl2 and ctl3, plus there's one Control object. This control does have a name because the Control class has a Name property. That property has no relationship whatsoever to the variables that may refer to the object.

    Now, hopefully I've demonstrated that what you've asked for makes no sense, so please explain what the intended functionality is and we can try to advise how to achieve it.

    Ok, My probs is this :

    I have a Class file Authentication.cs

    I want to create n number of authentication class objects...
    objects ....

    thankzzz
    gh

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    fgh
    Posts
    332

    User defined Class Arrays

    Quote Originally Posted by sureshvijayan
    Ok, My probs is this :

    I have a Class file Authentication.cs

    I want to create n number of authentication class objects...

    thankzzz


    I have a Class file Authentication.cs

    I want to create n number of authentication class objects...
    gh

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: want to set "Object variable name" dynamically ...

    Can't you simply create a collection of Authentication objects?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: want to set "Object variable name" dynamically ...

    As stanav suggests, if you want multiple objects of a type then create multiple objects of that type and put them in a collection. You could use a List(Of Authentication) or, if you want each one identified by a unique string, a Dictionary(Of String, Authentication).

    The collections I mention are only available from .NET 2.0. As you haven't specified your version I will assume that that's what you're using. Please specify in future regardless.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width