Results 1 to 6 of 6

Thread: EXCLUDE control from a looping

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    2,140

    EXCLUDE control from a looping

    Code:
    Private Sub PULISCI_TUTTO_ESCLUSO()
    
        Dim CTL As Control, TIPO As String
    
        For Each CTL In Me.Controls
            If TypeOf CTL Is ComboBox Then
                TIPO = CTL.Name
                If TIPO <> "CDARRIVO" Or TIPO <> "CTIPALLOGGIATO" Then
                    Debug.Print CTL.Name
                    CTL.Text = ""
                End If
            End If
        Next CTL
    
    End Sub
    why the <> dont work!
    in debug.print have CDARRIVO!!!! or CTIPALLOGGIATO!!!!

  2. #2
    Addicted Member Wolfgang Enzinger's Avatar
    Join Date
    Apr 2014
    Location
    Munich, Germany
    Posts
    150

    Re: EXCLUDE control from a looping

    Quote Originally Posted by luca90 View Post
    Code:
    Private Sub PULISCI_TUTTO_ESCLUSO()
    
        Dim CTL As Control, TIPO As String
    
        For Each CTL In Me.Controls
            If TypeOf CTL Is ComboBox Then
                TIPO = CTL.Name
                If TIPO <> "CDARRIVO" Or TIPO <> "CTIPALLOGGIATO" Then
                    Debug.Print CTL.Name
                    CTL.Text = ""
                End If
            End If
        Next CTL
    
    End Sub
    why the <> dont work!
    in debug.print have CDARRIVO!!!! or CTIPALLOGGIATO!!!!
    Reconsider the conditions ... at least one of them applies to every control.

    Try with And instead of Or.

    Wolfgang

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    2,140

    Re: EXCLUDE control from a looping

    Quote Originally Posted by Wolfgang Enzinger View Post
    Reconsider the conditions ... at least one of them applies to every control.

    Try with And instead of Or.

    Wolfgang
    NOT understAND...can you modify, my code.Tks

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,336

    Re: EXCLUDE control from a looping

    Replace the "Or" operator with "And". I will try to explain what is happening, in your test "CDARRIVO" may be matched while "CTIPALLOGGIATO" is not. Or the other way around. This results in the following situation:

    True Or False = True
    False Or True = True

    When using the Or operator you're asking for both controls not to be found in a single loop instead of either one or the other.

    True And False = False
    False And True = False
    Last edited by Peter Swinkels; May 8th, 2021 at 05:19 AM. Reason: typo

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,209

    Re: EXCLUDE control from a looping

    Code:
    If TIPO <> "CDARRIVO" And TIPO <> "CTIPALLOGGIATO" Then

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,521

    Re: EXCLUDE control from a looping

    Or you could also write it like
    Code:
    If Not (TIPO = "CDARRIVO" Or TIPO = "CTIPALLOGGIATO") Then

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