Results 1 to 6 of 6

Thread: Loop Through Buttons And Skip Certain Ones

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Loop Through Buttons And Skip Certain Ones

    This is probably one of those crazy simple things, but it's been a long day and I'm having trouble figuring it out.

    I loop through all of the buttons in a panel. If the button's name is not the name of the btnFunction, then I need to add that control to a list. But it adds the function button either way.

    Code:
    For Each c As Control In Me.pnKybdNormal.Controls
                If TypeOf c Is Button Then
                    If Not CType(c, Button).Name = btnFunction.Name Then
                         'Everything works correctly, except the btnFunction isn't skipped
                    End If
                End If
            Next
    Anyone know what I'm doing wrong here?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Loop Through Buttons And Skip Certain Ones

    Works fine this end.

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Loop Through Buttons And Skip Certain Ones

    It doesn't make sense why that wouldn't work. Try this
    Code:
    If c IsNot btnFunction Then
         'work
    End If
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  4. #4
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: Loop Through Buttons And Skip Certain Ones

    Thats odd works here

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Loop Through Buttons And Skip Certain Ones

    Will probably have the same result if your first post does not work...

    vb Code:
    1. Dim buttons = Me.Controls.OfType(Of Button).ToArray.Where(Function(b As Button) Not b.Name = btnFunction.Name)
    2. Array.ForEach(buttons.ToArray, Sub(b As Button) b.BackColor = Color.Black)

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Loop Through Buttons And Skip Certain Ones

    Your code works perfect here!!!

    Try to add break point and check control names.

    Also when something be crazy, i try a crazy code.

    vb Code:
    1. If String.Compare(CType(c, Button).Name, btnfunction.Name, True) = 0 Then
    2.     ' just skip
    3. Else
    4.       ' do something
    5. End If



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