-
Aug 1st, 2020, 03:50 AM
#1
Thread Starter
New Member
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
-
Aug 1st, 2020, 01:54 PM
#2
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!
-
Aug 1st, 2020, 05:37 PM
#3
Hyperactive Member
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.
-
Aug 2nd, 2020, 02:18 AM
#4
Re: VBRichClient5 cCollection ItemExists Question
Also with ItemExists? Or do you check for the existence of a key?
-
Aug 2nd, 2020, 03:34 AM
#5
Re: VBRichClient5 cCollection ItemExists Question
Originally Posted by Little John
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>
-
Aug 2nd, 2020, 05:58 AM
#6
Thread Starter
New Member
Re: VBRichClient5 cCollection ItemExists Question
Hello,
it is version 5.0.75.
Wolfgang
-
Aug 2nd, 2020, 10:41 AM
#7
Hyperactive Member
Re: VBRichClient5 cCollection ItemExists Question
Originally Posted by Arnoutdv
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!
-
Aug 3rd, 2020, 08:24 AM
#8
Re: VBRichClient5 cCollection ItemExists Question
Originally Posted by AAraya
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.
-
Aug 5th, 2020, 11:14 AM
#9
Re: VBRichClient5 cCollection ItemExists Question
Originally Posted by jpbro
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|