Substitution parameter for creating multiple objects

bryggya
01-13-2008, 09:41 AM
I'm using the header fields from a csv file and a collection of User attributes from Active Directory to create a mapping form displaying the array of csv fields in one column and list boxes of the collection in the adjacent comlumn.

I want to programatically generate list boxes, each one with a suffix value that corresponds to the array index number for the csv column. So what I need to figure out is if there's a substitution parameter available in VB 6.0 that will read the counter variable in a For loop as a literal value.

Here's the concept in rather abbreviated logic
csvlist = ubound(csvfields)
For a in csvlist
Dim Listbox_"a" as Listbox 'Give index suffix so you create the temp objects
'Listbox_1,Listbox_2...
For Each ADattr in Usrattr.collection 'repeat
Listbox_"a".additem ADattr.name
Next
Next

The intention is to provide flexibility to the form, as there could be varying numbers of header fields (20 to 30), so that the corresponding column pairs:
csv_header = listbox_value can then be written to a configuration file.

Thought this would be the easiest way to map a group of fix values to anothe r (the AD User collection) that has dozens of possible selections.

JPB
01-13-2008, 11:47 AM
I think what you need to do is create a control array for your ListBox. To do this, draw a ListBox on your form (named ListBox1), then set the Index property to 0 for that control. Draw as many additional ListBoxes as you require, naming them all ListBox1. You can now reference them by ListBox1(x) where x is an integer starting at 0 for the first ListBox, 1 for the second, etc...

You can also dynamically add ListBoxes to the array at runtime with Load Me.ListBox1(Me.ListBox1.Count). Be sure to set .Visible = True and the .Left, .Top properties so that the new listbox doesn't overlap an existing one.

bryggya
01-13-2008, 12:17 PM
Thanks, will try that. Just curious, is your code exampe for .NET? I'm using vb 6.0. Still wondering if you can have the compiler read a variable as a literal, would come in handy.

JPB
01-13-2008, 02:26 PM
The code is for VB6. You can refer to controls by name with:

Me.Controls(strCtrlName)

But the downsides are that it is slower and you lose Intellisense when programming in the IDE.

mkaras
01-13-2008, 07:43 PM
Still wondering if you can have the compiler read a variable as a literal, would come in handy.

Please consider that the variables of the FOR loop take on their values at run time ... not at compile time. The compilation process is a source code to run time code conversion process and so thing you are asking the compliler to do is not really possible. You are asking for the run time to process to be injected into the compilation process when such latter process is actually trying to create said run time process. Sounds kind of "cart before the horse" doesn't it.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum