473,408 Members | 2,888 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,408 software developers and data experts.

Loop Question

....another beginner question - using visual web 2005 with VB

I have 20 labels - lbl1 through lbl20

I have a listbox containing values 1 through 20

I need to make label 1 through the selected value of the listbox visible, but the rest of the labels invisible

I'm assuming that the best way to do this is with 2 loops in the listbox click event something like:
for i = 1 to listbox1.selectedvalue
lbl i .visible = true
next

for i = listbox1.selectedvalue+1 to 20
lbl i.visible = false
next
....but I'm not sure how to actually code this.

Can someone point me in the right direction?

Thanks in advance

Jeff

--
Posted via a free Usenet account from http://www.teranews.com

Sep 3 '06 #1
2 1312
Hello Jeff,

Were it me I would use the TAG proeprty.. just because I dont like concatinating
control names.. Start with the first label and set it's tag proeprty to 1,
then the next to 2, and so on..

Then your loop will be something like this (assuming all numbers from 1 through
listbox1.selectedvalue are to be made visible and all others invisible..) :
Dim tControl as Control = Nothing
Dim tCount as Integer = 0
For Each tControl In Me.Controls
tCount = 0
Integer.TryParse(tControl.Tag, tCount)
If 0 < tCount Then
If tCount <= ListBox1.SelectedValue
tControl.Visible = True
Else
tControl.Visible = False
End If
End If
Next
The above code does not touch control within containers.. you can figure
that part out.

-Boo

...another beginner question - using visual web 2005 with VB

I have 20 labels - lbl1 through lbl20

I have a listbox containing values 1 through 20

I need to make label 1 through the selected value of the listbox
visible, but the rest of the labels invisible

I'm assuming that the best way to do this is with 2 loops in the
listbox click event something like:

for i = 1 to listbox1.selectedvalue
lbl i .visible = true
next
for i = listbox1.selectedvalue+1 to 20
lbl i.visible = false
next
...but I'm not sure how to actually code this.

Can someone point me in the right direction?

Thanks in advance

Jeff

Sep 3 '06 #2
Jeff wrote:
<snip>
I have 20 labels - lbl1 through lbl20
I have a listbox containing values 1 through 20
I need to make label 1 through the selected value of the
listbox visible, but the rest of the labels invisible
I'm assuming that the best way to do this is with 2 loops
in the listbox click event something like:
for i = 1 to listbox1.selectedvalue
lbl i .visible = true
next

for i = listbox1.selectedvalue+1 to 20
lbl i.visible = false
next
<snip>

Consider keeping the labels in an array, declared at the top level of
the form:

<aircode>
Private mLabels() As Label = New Label() { _
Lbl1, Lbl2, Lbl3, Lbl4, Lbl5, _
Lbl6, Lbl7, Lbl8, Lbl9, Lbl10, _
Lbl11, Lbl12, Lbl13, Lbl14, Lbl15, _
Lbl16, Lbl17, Lbl18, Lbl19, Lbl20 _
}
</aircode>

Then in the event that actually toggles the visible property, you can
use one or two loops, whatever suits you:

<aircode>
'Gets the relevant item
Dim Index As Integer = Integer.Parse(ListBox1.SelectedValue.ToString)

'One Loop
For I As Integer = 0 to mLabels.Length - 1
mLabels(I).Visible = I < Index
Next

'Two loops
For I As Integer = 0 to Index-1
mLabels(I).Visible = True
Next

For I As Integer = Index to mLabels.Length-1
mLabels(I).Visible = False
Next
</aircode>

Regards,

Branco.

Sep 4 '06 #3

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

Similar topics

33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
0
by: John Wilson | last post by:
Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and stored procedure which takes @DemoID as input to match...
3
by: zeroDoNotYeSpamtype | last post by:
(I tried to post this earlier, but it seems without success) A similar question to this has been answered many times, to whit the question applying when the index variable of a for loop is...
3
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the...
22
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
3
by: nina297 | last post by:
Good morning, How do I set up a For each loop to loop through my records in the database? My fields are topics, question and answers. I want the one topic displayed that goes with each...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
2
by: perkykoala | last post by:
I apologize in advance for being REALLY detailed/verbose. It's the result of staring/tweaking code for too long. Using VB 2005: I need to design a multiple choice test (unfortunately, I can't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.