Consulting

Results 1 to 5 of 5

Thread: Combine 2 Codes

  1. #1

    Combine 2 Codes

    I have 2 listbox in a userform. The code below is to un-tick all ticked items in both list boxes. The code works well, but in an effort to write effiecient coding, I would combine the two coding into one. Can someone provide some assistance?

     
            With Me.ACLIST
                EnableEvents = True
                For j = 0 To .ListCount - 1
                    If j = .ListCount - 1 Then EnableEvents = False
                    .Selected(j) = False
                    Call ResetLB
                Next
            End With
            With Me.APPCH
                EnableEvents = True
                For j = 0 To .ListCount - 1
                    If j = .ListCount - 1 Then EnableEvents = False
                    .Selected(j) = False
                    Next
                End With

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No point. The listcounts could be different which would mean testing in the loop, very inefficient.

    You could havce a generic lisbox handler and pass the listbox to that, but I wouldn't bother, and that call throws it anyway.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thank you Xld for you insight.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No problem, the code is fine, it works, it looks good, no more to do
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    One thing I just thought, insteda of loopping all items and testing for the last and turning off events, why not do it like so

    [vba]

    With Me.ACLIST
    EnableEvents = True
    For j = 0 To .ListCount - 1
    .Selected(j) = False
    Call ResetLB
    Next
    EnableEvents = False
    End With
    [/vba]

    saves the test
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •