|
-
Oct 19th, 2007, 03:44 AM
#1
Thread Starter
Hyperactive Member
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
-
Oct 19th, 2007, 04:16 AM
#2
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:
Dim obj1 As New Object
Dim obj2 As Object = obj1
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:
Dim ctl1 As New Control
ctl1.Name = "A new control"
Dim ctl2 As Control = ctl1
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.
-
Oct 19th, 2007, 04:50 AM
#3
Thread Starter
Hyperactive Member
Re: want to set "Object variable name" dynamically ...
 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:
Dim obj1 As New Object
Dim obj2 As Object = obj1
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:
Dim ctl1 As New Control
ctl1.Name = "A new control"
Dim ctl2 As Control = ctl1
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
-
Oct 19th, 2007, 05:38 AM
#4
Thread Starter
Hyperactive Member
User defined Class Arrays
 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...
-
Oct 19th, 2007, 11:38 AM
#5
Re: want to set "Object variable name" dynamically ...
Can't you simply create a collection of Authentication objects?
-
Oct 19th, 2007, 07:39 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|