473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Populating labels from an array

Ian
I have 5 labels on my form called Label1 to Label5.
I wish to populate each label with data stored in a simple string array.

e.g.

For i = 0 to 4
Label(i).text = array(i)
Next i

In VB6 I simply used a control array, but in .Net all controls require a
unique name. How would I write the above in .Net?

Ian
Nov 20 '05 #1
2 2079
Hi,

Here is a link on how to create control arrays.
http://msdn.microsoft.com/library/de...et05132003.asp

Ken
---------------------
"Ian" <ih****@hotmail.com> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
I have 5 labels on my form called Label1 to Label5.
I wish to populate each label with data stored in a simple string array.

e.g.

For i = 0 to 4
Label(i).text = array(i)
Next i

In VB6 I simply used a control array, but in .Net all controls require a
unique name. How would I write the above in .Net?

Ian

Nov 20 '05 #2
Cor
Hi Ian,

For normal purpose (not dynamicly making controls) you don't need the
control array. You can loop through controls.

Keep in mind that a control is always a child of his parent.

I take your example and make it the same in a for each loop.
I know this sounds a little bit strange and you can think on a control
array,
on the other hand here you have an example how to do that without it when
your labels (childs) are direct on the form (parent)

This example is very quick and dirty written so watch typos and small errors
\\\
dim ctr as control
for each ctr in me.controls
if typof ctr is label then
if ctr.name.substring(0,5) = "label" then
ctr.text = array(ctr.name.substring(5,1))
end if
end if
next
///

Of course when you have more labels with the name label, you should test
first if the labelname was between label1 and label5
For i = 0 to 4
Label(i).text = array(i)
Next i

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: madeo | last post by:
hi, i'm looking for some script which would export address labels from a mysql db to pdf ... There's an exapmle, but i'm not able to convert it for using with mysql ... can anybody help? THX...
2
by: tony collier | last post by:
hi i have various labels on my page with ID's label_1, label_2 , label_3 etc. How can i write a loop that sequentially changes their text values to values i have in an array eg;. for...
3
by: luna | last post by:
theres no errors in my code - but it does nothing at all - its supposed to be populating text boxes!! any ideas ? (im am pretty new to all this) If Not Page.IsPostBack Then Dim search As...
1
by: Neal | last post by:
I need to create many labels to fit on a windows forms and instead of using the designer to create a large number of text labels I just wanted to make an array of them and then loop through them to...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
3
by: gediko | last post by:
hi all, i am creating a series of labels, which the number of labels is defined by the user. dim labels( ) as label after learning the number, redim labels(i) then i am changing their...
3
by: parkergirl | last post by:
Hi, I have an msflexgrid that I need to select with checkboxes (I'm currently using WingDings font). The selection of rows cannot be anymore than three rows (randomly). Then, I need to take the...
4
by: Peter Duniho | last post by:
On Thu, 14 Aug 2008 18:56:00 -0700, Phill <Phill@discussions.microsoft.comwrote: For future reference, if you are asking for help with an error (compile or execution), you really should post...
0
by: jac130 | last post by:
i need to populate an array with grades. there is an 'add students & grades' button. user is prompted by input box to enter a students name, then another input box to enter their grade. the student's...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.