Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Literal substitution - instantiate form objects using variables as literals


Reply
 
Thread Tools Display Modes
  #1  
Old 10-23-2008, 07:19 AM
bryggya bryggya is offline
Newcomer
 
Join Date: Jan 2008
Posts: 8
Default Literal substitution - instantiate form objects using variables as literals


What I need to do is create comboboxes populated with values from a CSV for each class object selected from an Active Directory schema.

So lets say twelve classes are selected, the next form will display the class names in a checkedlistbox and will require twelve comboboxes for associating AD classes to CSV fields. Since the number of AD classes selected will always vary, is there a practical way to code it so that the objects can be instantiated from values stored in a variable?

Other languages support macro substitution, where the variable's value is interpreted as a literal at runtime.

Developing in Visual Studio 2005, VB version 8 .netFramework 2.0xxx
Reply With Quote
  #2  
Old 10-23-2008, 08:34 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
Default

This is a really, really, really, really common question on this forum. Three times a week common. The main problem is that most people get stuck on "$language lets me do it this way" and assume that either .NET must support it that way or not at all.

Well, in truth, .NET doesn't support using a string literal to refer to a variable. Well, in truth, it doesn't support it in a way that you want to use; the reflection code would be large and slow.

The best way to work around this is to use a control array. Decide how many combo boxes you need, then pass that information to your form. It can make an array of the appropriate size, instantiate and configure the combo boxes, then lay them out in a desirable pattern.

Keep in mind that you're not limited to just using arrays; you could use a List or other data structure to better support on-the-fly changes in the number of combo boxes.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 10-23-2008, 08:47 AM
bryggya bryggya is offline
Newcomer
 
Join Date: Jan 2008
Posts: 8
Default Makes sense

Thanks for the information. If you have any other examples, please let me know.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->