Google Answers Logo
View Question
 
Q: VB.Net - No More Control Arrays!? ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: VB.Net - No More Control Arrays!?
Category: Computers > Programming
Asked by: rhodylady-ga
List Price: $2.00
Posted: 22 Nov 2002 07:10 PST
Expires: 22 Dec 2002 07:10 PST
Question ID: 112537
I'm now using VB.Net.  In VB version 6 we had control arrays.  I could
set up an array of, say, labels and each label would have its own
index value.  I could access each element of the control array by
using its index value:  myLabel(3).Caption = "hi"

Here's my problem.  I have an array of integers. Each slot in the
array has a unique number.  I'd like to display each of these elements
in a label.  I want the first element of the array to go into the
first label, the second element of the array in the second label, etc.
 I want to make sure that each element of the array goes into its
"matching" label (1st in the 1st, 4th in the 4th, etc.).

In VB version 6 I could have an array of integers named MyArray, and a
control array of labels named MyLabels, and do something like this:

For X = 0 to 5
   MyLabel(x).Caption = MyArray(x)
Next X

How can SIMPLY accomplish the same task in VB.Net? I've looked at
label collections, controls collections, sortedlists, creating my own
class, and I'm just getting more confused.
Answer  
Subject: Re: VB.Net - No More Control Arrays!?
Answered By: theta-ga on 22 Nov 2002 09:55 PST
Rated:5 out of 5 stars
 
The following Google Groups posting, provides a number of ways to get
around the lack of control arrays in Vb.net and is recommended reading
:
  - Google Group : microsoft.public.vsnet.general
    Control Arrays in VB.NET?
    ( http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=ekeahbyiBHA.1544%40tkmsftngp02&rnum=5&prev=/groups%3Fq%3Dcontrol%2Barrays%2Bvb.net%26hl%3Den%26lr%3D%26ie%3DUTF-8%26sa%3DN%26tab%3Dwg
)

As you can see from the above article, if you want to set your label
property repeatably in a loop, and your User Interface design allows
it, you should probably put them in a Panel and use a For Each/next
loop to set the values.
 Otherwise, create an array of references to a Label ( as shown in the
posting) and assign each array element one of the labels.

If you are interested in finding out how you can duplicate the
functionality of control arrays programmatically, read the following
articles :
  - MS Whitepaper : Creating Control Arrays in Visual Basic .NET and
Visual C# .NET
    by Matthew A. Stoecker
    ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingcontrolarraysinvisualbasicnetvisualcnet.asp
)

  - Creating and using control arrays in Visual Basic. NET and C#
    By Parikshith Moola 
    ( http://www.codeproject.com/useritems/Control_Arrays_in_NET.asp )
========
Hope this helped.
If you need any clarifications, just ask!
Happy coding!
rhodylady-ga rated this answer:5 out of 5 stars
Thank you.  It's the answer I was afraid of - but I'm glad to have my
suspicions confirmed (that I have to use the .Tag property)

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy