Results 1 to 8 of 8

Thread: multiple labels looping

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2004
    Location
    Vancouver, BC, Canada
    Posts
    23

    Question 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

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  3. #3
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    perhaps
    VB Code:
    1. Dim c As Control
    2.       For Each c In Me.Controls
    3.          If TypeOf c Is Label Then
    4.             'blah blah'
    5.          End If
    6.       Next

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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.

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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:
    1. Dim c As Control
    2.       Dim intX as Integer=0
    3.       For Each c In Me.Controls
    4.          If c.Tag="YES" Then
    5.             c.Text=str(dteShiftWeek(intX))
    6.             intx=intx+1
    7.          End If
    8.       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.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2004
    Location
    Vancouver, BC, Canada
    Posts
    23
    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

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Try

    VB Code:
    1. Dim c As Control
    2. For Each c In Me.Controls
    3.       Dim intSet As Byte
    4.       If c.Name.Substring(0, 6) = "chkSet" And Len(c.Name) = 8 Then
    5.            intSet = c.Name.Substring(6, 2)
    6.            If dteSets(intSet) = m_dtTimeOff.Rows(intCnt)("Day") Then
    7.               blnSet(intSet) = True
    8.               If TypeOf c Is CheckBox Then
    9.                 CType(c, CheckBox).Checked = True
    10.             End If
    11.            End If
    12.       End If
    13. 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.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jun 2004
    Location
    Vancouver, BC, Canada
    Posts
    23

    * 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
  •  



Click Here to Expand Forum to Full Width