Results 1 to 9 of 9

Thread: VBRichClient5 cCollection ItemExists Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Posts
    12

    VBRichClient5 cCollection ItemExists Question

    Hello,

    the following code gives me puzzles.

    Code:
      Dim c1 As vbRichClient5.cCollection
      Dim c2 As vbRichClient5.cCollection
      Set c1 = New_c.Collection
      Set c2 = New_c.Collection
    
      c1.Add "P04" ', "P04"
      Debug.Print c1.ItemExists("P04") 'it is false !!!!
    
      c2.Add "P04" ', "P04"
      c2.Add "P12" ', "P12"
      Debug.Print c2.ItemExists("P04")  'it is true - why???
    Why is c1 not true?

    What's my mistake?

    Wolfgang

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: VBRichClient5 cCollection ItemExists Question

    Looks like a bug. I've found the source of the problem and I will report it to Olaf, thanks for posting the question and test code!

  3. #3
    Hyperactive Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    416

    Re: VBRichClient5 cCollection ItemExists Question

    What causes this bug to occur? The sample code looks like something I'm doing all over my code and I've not noticed this problem.

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    Re: VBRichClient5 cCollection ItemExists Question

    Also with ItemExists? Or do you check for the existence of a key?

  5. #5
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: VBRichClient5 cCollection ItemExists Question

    Quote Originally Posted by Little John View Post
    Hello,

    the following code gives me puzzles.

    Code:
      Dim c1 As vbRichClient5.cCollection
      Dim c2 As vbRichClient5.cCollection
      Set c1 = New_c.Collection
      Set c2 = New_c.Collection
    
      c1.Add "P04" ', "P04"
      Debug.Print c1.ItemExists("P04") 'it is false !!!!
    
      c2.Add "P04" ', "P04"
      c2.Add "P12" ', "P12"
      Debug.Print c2.ItemExists("P04")  'it is true - why???
    Why is c1 not true?

    What's my mistake?

    Wolfgang
    Which version of RC5 do you test this on?

    cheers,
    </wqw>

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Posts
    12

    Re: VBRichClient5 cCollection ItemExists Question

    Hello,

    it is version 5.0.75.

    Wolfgang

  7. #7
    Hyperactive Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    416

    Re: VBRichClient5 cCollection ItemExists Question

    Quote Originally Posted by Arnoutdv View Post
    Also with ItemExists? Or do you check for the existence of a key?
    You are correct - I am doing a key-based search using the Exists method. Thanks for pointing that out!

  8. #8
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: VBRichClient5 cCollection ItemExists Question

    Quote Originally Posted by AAraya View Post
    What causes this bug to occur? The sample code looks like something I'm doing all over my code and I've not noticed this problem.
    The bug is due to a logic error in the string comparison code of the .ItemExists method. It returns True whenever an item that *doesn't* match the passed value is found, instead of returning True only when finding a match (the logic is backward). Note that the (more commonly used) .Exists method is fine.

    I've reported the problem to Olaf, so I'm hopeful that a fix should be forthcoming - he's usually quick to respond to issues.

  9. #9
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VBRichClient5 cCollection ItemExists Question

    Quote Originally Posted by jpbro View Post
    I've reported the problem to Olaf, so I'm hopeful that a fix should be forthcoming ...
    Just uploaded a new version (5.0.79), which should ensure the correct behaviour now...

    As already pointed out, this is (other than the (Key)Exists-Method) a rarely used method.

    Also note, that it is also not the fastest method, because it does kind of a:
    - "FullTableScan without using Binary-Search" (to determine, whether an Item-Value exist in the List, or not).

    @Wolfgang (Little John)
    I'd suggest (when the scenario is, to add only single Values, and not Key-Value-Pairs) -
    to just use the cSortedDictionary instead, which allows to add:
    - only the Key-Values (without any accompanying Item-Values) in its Add-Method
    The search for existence on such a "Keys-only-Dictionary" will make use of the fast Binary-Search then...

    HTH

    Olaf

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