473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sub(Thing as Object) {thing = new Thing.GetType} ?

Hello,
Sorry for polluting the VB newsgroup with curly brackets, but I couldn't
think how to get that question onto one line otherwise.
Anyway, I'm trying to write a Sub, or Function which takes an object as an
input and then creates a new object of the same type using that class'
constructor.
VB isn't currently liking any of my attempts, but the general idea is to
have:

Private Function NewInterfaceObjectArray(ByVal InterfaceObject As
Object(), ByVal defaultValue As Integer) As InterfaceObjectClass()
InterfaceObject = New InterfaceObject.GetType
Return InterfaceObject
End Function
That's a bit messy, even for pseudocode, but I think you'll get the idea..

I guess this is a bit of a weird question, but it's mostly because the
idea intrigued me while I was writing a long constructor for an object
made of object arrays, which were all interfaces onto a single object
type. I'm *sure* there was a good reason for coding that at the time...

Anyway, I can get round the problem, but I'm interested in whether the
language supports the idea of the function I'm asking about, and the
question seems to be too obscure for google (or my use of google) to cope
with.

KF
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Sep 22 '06 #1
1 950
"Kristian Frost" <kf****@gmail.comschrieb:
>Sorry for polluting the VB newsgroup with curly brackets, but I couldn't
think how to get that question onto one line otherwise.
Anyway, I'm trying to write a Sub, or Function which takes an object as an
input and then creates a new object of the same type using that class'
constructor.
Obtain the type of the object passed to the method by calling its 'GetType'
method. Then pass the type to 'Activator.CreateInstance' to create an
instance of the type.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 22 '06 #2

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

Similar topics

44
by: Steven T. Hatton | last post by:
This may seem like such a simple question, I should be embarrassed to ask it. The FAQ says an object is "A region of storage with associated semantics." OK, what exactly is meant by "associated...
3
by: Jenni | last post by:
Hi, my simple solution is not so simple. I have done a bit of VB programming, and am now tasked with trying to make access work using VBA, and battling my butt off. This probably has a really...
5
by: Lars Moastuen | last post by:
Hi! I'm currently playing around with a project where I need to know if an object (any object) has been altered since last check. I need this to know when an object needs to be saved... My idea...
1
by: Sam Fields | last post by:
I have been wrestling with this code for about 2 weeks now. My goal is to create a table for formatting purposes. I want to standardize it as a webcontrol. I want all of the content to persist...
4
by: craig | last post by:
During construction of an object "parent", if you create a subobject that stores a pointer to the parent (through the "this" pointer), will that pointer be valid when the subobject is later called?...
0
by: bradtwurst | last post by:
Hello all, I have a webservice that I am calling via wsdl.exe generated code that is missing sub-objects when the soaphttpclientprotocol.invoke method is called. The basic layout is ...
2
by: chris fellows | last post by:
In VS2005 (C#) I want to set the properties of an object dynamically at runtime from an XML configuration file but without having to know the property name when writing the code. The properties are...
8
by: Anand | last post by:
I am trying to implement some kind of object inheritance. Just like one class can extend from another, I want to do the same on objects dynamically. I just thought that I can share my excitement...
23
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.