Execute() alternative ?

  • Thread starter Thread starter Morgan
  • Start date Start date
M

Morgan

Hello, all

I am currently doing the following:

lblPrice1.Text = arrPrices(1)
lblPrice2.Text = arrPrices(2)
lblPrice3.Text = arrPrices(3)
lblPrice4.Text = arrPrices(4)
lblPrice5.Text = arrPrices(5)

But I'd like to change it so it is done dynamically. I would like to
do something like:

Dim NUMPRODUCTS As Integer = 5
For i As Integer = 1 To NUMPRODUCTS
Execute( "lblPrice" & i & ".Text = arrPrices(" & i & ")" )
Next

I've read that I can do a complicated process of saving the code as a
DLL and then executing it, but I'd prefer a built-in function. Any
pointers?

Thanks,
Morgan Seppy
 
Morgan,

There are more posibilities for your problem:
1 name your tags accoording to the way you want to fill it and use that in a
for each loop
2 name your labelnames accoording to the way you want to fill it
3 create an control array with the references and use that
4 etc.

I give you an example of the 3th, typed here so watch typos and not tested
\\\
Dim lbls As Label() = New Label() {nothing,LblPrice1,lblPrice2, etc...5}
for i as integer = 1 to 5
lbls(i) = arrPrices(i)
next
///
One of the big advantage from this one is that the label can (also) be on
different containers withouth doing more loops.

It is easier by the way to go in VBNet to zero indexers. Those are not
logical in my opinion, however. only the typical VB namespace methods use
the one type indexers and this is for many of us confusing.

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top