|
-
Jun 18th, 2004, 01:23 PM
#1
Thread Starter
Junior Member
multiple labels looping
This is my first project in VB.Net and am learning on the fly. Have some C++ experience.
Have a ListView of employees that user chooses and brings up a form with 46 different labels and 46 different check boxes
How do I create a looping routine that changes the labels to the values that I need, instead of changing each label manually (lblWeek01.text="01/05/2005"), (lblWeek02.text="01/10/2005")
I have an array of dates:
Public dteShiftSets(45) As Date
dteShiftSets(0) = #01/05/2005#
For intX As Integer = 1 To 45
'adds 8 days to each new element in array
dteShiftWeek(intX) = DateAdd(DateInterval.Day, 8, dteShiftWeek(intX - 1))
Next
I need to display all 46 array elements (the dates I've just assigned them) beside the corresponding checkbox
chkWeek00, chkWeek01, ... chkWeek45
Is my only option coding each label individually, ie
lblWeek00.text = dteShiftWeek(0)
lblWeek01.text = dteShiftWeek(1), etc
or is there some sort of loop that I can use that will increment the lblWeek??. The looping part is easy how do I increment the label to accept the array element (date that I've assigned)
For intX as Integer = 0 to 45
xxxxxxxxxx.text = dteShiftWeek(intX)
Next
If this was just a one timer, I would just hard code each one, but I need something similar for other parts of the program.
Any help would be appreciated
Shozy
-
Jun 18th, 2004, 06:18 PM
#2
PowerPoster
Hi,
In VB.NET the easiest way to do this is to use Collections. Read up on the subject in MSDN Help, it is very helpful.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 18th, 2004, 08:29 PM
#3
Fanatic Member
perhaps
VB Code:
Dim c As Control
For Each c In Me.Controls
If TypeOf c Is Label Then
'blah blah'
End If
Next
-
Jun 19th, 2004, 07:39 AM
#4
Frenzied Member
46 checkboxes and labels is a lot for one form. Can you break it up somehow? Multiple forms, tab controls, etc? I worked on a Delphi project where one tab had @ 60 controls. Not all that hard to code but a pain in the butt for the user.
-
Jun 19th, 2004, 07:33 PM
#5
PowerPoster
Hi,
Referring to brown monkey's post, if some of the labels on the form were not used for dates, then identify those which are and set their Tag property to something (e.g. "YES") and then code
VB Code:
Dim c As Control
Dim intX as Integer=0
For Each c In Me.Controls
If c.Tag="YES" Then
c.Text=str(dteShiftWeek(intX))
intx=intx+1
End If
Next
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 9th, 2004, 01:18 AM
#6
Thread Starter
Junior Member
Finally got back into it. Thanks for the info, works great
Here is my next problem with this loop:
When it loops through each control it only lets me change basic properties (ie c.enable), it won't let me change a specific property to the checkbox control (ie c.checked)
How do I change the value of c.checked ? Thanks in advance
'dteSets() is an array of dates
Code:
Dim c As Control
For Each c In Me.Controls
Dim intSet As Byte
If c.Name.Substring(0, 6) = "chkSet" And Len(c.Name) = 8 Then
intSet = c.Name.Substring(6, 2)
If dteSets(intSet) = m_dtTimeOff.Rows(intCnt)("Day") Then
blnSet(intSet) = True
c.Enabled = False 'this works
'c.checked = True 'this won't build, even if I continue-nothing
End If
End If
Next c
-
Jul 9th, 2004, 06:26 AM
#7
PowerPoster
Hi,
Try
VB Code:
Dim c As Control
For Each c In Me.Controls
Dim intSet As Byte
If c.Name.Substring(0, 6) = "chkSet" And Len(c.Name) = 8 Then
intSet = c.Name.Substring(6, 2)
If dteSets(intSet) = m_dtTimeOff.Rows(intCnt)("Day") Then
blnSet(intSet) = True
If TypeOf c Is CheckBox Then
CType(c, CheckBox).Checked = True
End If
End If
End If
Next c
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 9th, 2004, 10:27 AM
#8
Thread Starter
Junior Member
* problem resolved *
Thanks taxes, it worked great!
Problem resolved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|