Literal substitution - instantiate form objects using variables as literals

bryggya
10-23-2008, 07:19 AM
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

AtmaWeapon
10-23-2008, 08:34 AM
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 (http://www.xtremevbtalk.com/showthread.php?t=174835). 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.

bryggya
10-23-2008, 08:47 AM
Thanks for the information. If you have any other examples, please let me know.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum