Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 29th, 2005, 01:12 PM
Authorized User
Points: 325, Level: 6
Points: 325, Level: 6 Points: 325, Level: 6 Points: 325, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Altamonte Springs, FL
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can I create a class from a variable?

Hi:

I have a variable, RptName.
I've got a slew of classes that represent reports, such as:
RptCAMainSum
RptTPEMainSum
etc.

If the value of RptName = "RptCAMainSum" then I want the class:
RptCAMainSum
If the value of RptName = "RptTPEMainSum" the I want the class:
RptTPEMainSum

Of course I could use a long if() else if() block but if I can, I'd rather find a way to call the class from the value of the var.

Something like:
    IReport oReport = Class(RptName);

In Javascript I could say:
     var oReport = eval(RptName);
     this would return the object named whatever the value of RptName is.

I hope that makes sense.
Is there any way to do this?

__________________
http://www.softlinksys.com
Professional Software Developer since 1994.
Reply With Quote
  #2 (permalink)  
Old July 30th, 2005, 08:04 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This calls for Reflection. You can dynamically load types by name using the methods on classes found in System.Reflection.

-Peter
Reply With Quote
  #3 (permalink)  
Old August 1st, 2005, 11:57 AM
Authorized User
Points: 325, Level: 6
Points: 325, Level: 6 Points: 325, Level: 6 Points: 325, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Altamonte Springs, FL
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peter, I'll give it a try.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a new variable in javascript crmpicco Classic ASP Basics 2 February 2nd, 2005 12:53 PM
Cannot create a new class from VS 2k3 r_ganesh76 General .NET 0 November 3rd, 2004 05:21 AM
how to create Global Variable VIshwastrivedi SQL Server 2000 5 September 30th, 2004 08:38 AM
Invoking event from member variable class adxabuan Visual C++ 0 February 2nd, 2004 06:04 AM
How to create a class instance dynamic??? ffbalota C# 0 September 21st, 2003 04:49 PM



All times are GMT -4. The time now is 09:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.