473,748 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable type Object, assign to a Class at runtime

Hi all,

I have the problem to assign a variable of type object to
a specific class at runtime. I want to use a string
variable that specify the class a want to set this object.

Is something similar to add a new control to a form using
the controls collection:

Private Sub CommandCreateIn stance_Click()
Dim newInstance As Object
Dim strClass as String

strClass = "aClass"

Set newInstance = Me.Controls.Add ("VB." & strClass,
newInstanceName , Me)

End Sub

In the example 'aClass' is a Class I made as a Class
module, but with custom classes doesn't work, it has to be
a Control registered in VB.

Has anybody any idea to do this.

Thanks

Nov 20 '05 #1
4 4242
"Andres" <an************ *@catv.rol.ch> schrieb
Hi all,

I have the problem to assign a variable of type object to
a specific class at runtime.
You can not assign an object to a class. You can assign an object to a
variable with a certain type.
I want to use a string
variable that specify the class a want to set this object.
The string contains the class name? Where, when and how do you create the
object?
Is something similar to add a new control to a form using
the controls collection:

Private Sub CommandCreateIn stance_Click()
Dim newInstance As Object
Dim strClass as String

strClass = "aClass"

Set newInstance = Me.Controls.Add ("VB." & strClass,
newInstanceName , Me)

End Sub

In the example 'aClass' is a Class I made as a Class
module, but with custom classes doesn't work, it has to be
a Control registered in VB.

Has anybody any idea to do this.

I am not sure if it helps, but have a look at Activator.Creat einstance.
--
Armin

Nov 20 '05 #2
Andres,
I am not sure if it helps, but have a look at
Activator.Creat einstance. Where can I find this Activator and what is it?


Its a class in the system namespace

System.Activato r

http://msdn.microsoft.com/library/de...ClassTopic.asp

Hope this helps
Jay

"Andres" <an************ *@catv.rol.ch> wrote in message
news:0e******** *************** *****@phx.gbl.. .
-----Original Message-----
"Andres" <an************ *@catv.rol.ch> schrieb
Hi all,

I have the problem to assign a variable of type object to a specific class at runtime.


You can not assign an object to a class. You can assign

an object to a
variable with a certain type.


Ok, may be I didn't describe very well what I try to
do... I declare a variable as Object type

Dim newInstance as Object

then at runtime I want newInstance to point to an object
of class 'x' that the user can choose from a set of
classes types displayed in a combobox or whatever. So when
the user clicks the button insert new object the procedure
should receive a class name as a string variable, then
should create the object of class 'x' and should store the
reference in a collection of objects somewhere.

I want to use a string
variable that specify the class a want to set this object.

The string contains the class name? Where, when and how

do you create the
object?
Is something similar to add a new control to a form

using the controls collection:

Private Sub CommandCreateIn stance_Click()
Dim newInstance As Object
Dim strClass as String

strClass = "aClass"

Set newInstance = Me.Controls.Add ("VB." & strClass,
newInstanceName , Me)

End Sub

In the example 'aClass' is a Class I made as a Class
module, but with custom classes doesn't work, it has to be a Control registered in VB.

Has anybody any idea to do this.

I am not sure if it helps, but have a look at

Activator.Creat einstance.


Where can I find this Activator and what is it?

Andres
--
Armin

.

Nov 20 '05 #3
"Andres" <an************ *@catv.rol.ch> schrieb
-----Original Message-----
"Andres" <an************ *@catv.rol.ch> schrieb
Hi all,

I have the problem to assign a variable of type object to a specific class at runtime.


You can not assign an object to a class. You can assign

an object to a
variable with a certain type.


Ok, may be I didn't describe very well what I try to
do... I declare a variable as Object type

Dim newInstance as Object

then at runtime I want newInstance to point to an object
of class 'x' that the user can choose from a set of
classes types displayed in a combobox or whatever. So when
the user clicks the button insert new object the procedure
should receive a class name as a string variable, then
should create the object of class 'x' and should store the
reference in a collection of objects somewhere.


The mentioned activator class should solve this problem.
I am not sure if it helps, but have a look at

Activator.Creat einstance.


Where can I find this Activator and what is it?


where: in the object browser, by using the symbol search or in the docs.
what it is: what you are looking for. :-)
--
Armin

Nov 20 '05 #4
Hello,

"Andres" <an************ *@catv.rol.ch> schrieb:
I have the problem to assign a variable of type object to
a specific class at runtime. I want to use a string
variable that specify the class a want to set this object.


Are you sure you are talking about VB.NET?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

83
6513
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in C. It can cause very ugly errors,like this: epsilon=0 S=0 while epsilon<10: S=S+epsilon
6
2750
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid = server.createobject("scriptlet.typelib").guid guid=Left(guid,instr(guid,"}")) genguid=guid
5
1280
by: Patrick | last post by:
Hi I have a Problem with my static vector which I defined. I'm using LTIB Library looks like this: test.h class test { public:
16
25419
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have the properties: mode1, mode2, and mode3. This seems simple but I can't quite figure it out... Any ideas anyone?
134
7893
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that means that if I misspell a variable name, my program will mysteriously fail to work with no error message. If you don't declare variables, you can inadvertently re-use an variable used in an enclosing context when you don't intend to, or
166
8642
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
4
1649
by: Lucas Sain | last post by:
Hi, I think thta for this I have to use reflection... but I'm not shure. How can I find/get an object at runtime by looking for its name that is stored in a variable. For example: I have a DataTable called dtPersons that loads all the data of the persons. I have a string variable called tableVariable that stores tha name "dtPersons".
3
21221
by: mra | last post by:
I want to cast an object that I have created from a typename to the corresponding type. Can anycone tell me how to do this? Example: //Here, Create the object of type "MyClass" object obj=Activator.CreateInstance(strAssemblyName, "MyClass"); //Now, I want to do something like ((MyClass)obj).Method //Can I do this?
11
3561
by: JohnR | last post by:
I'm trying to find a way to create a variable of a given type at runtime where I won't know the type until it actually executes. For example, dim x as object = "hi" x is declared as an object but x.gettype returns 'string', so it knows it contains a string. If I want to create a variable "y" as the same type that variable x contains how would I do that without having to iterate thru every possible
0
8983
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9236
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8235
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.