VB6 ListView1.FindItem by key gets error '13'

StuckWithVB6StuckWithVB6 Little Rock, AR

' I've been pulling my hair out over this one, any help is greatly appreciated.

' I'm loading a VB6 ListView with up to 70K of items and populating the Key
' property of each item with the Add method. View=lvwReport.

' My interpretation of the docs is that I can provide either an index or a key
' in the "index" parameter of FindItem. If the data type of the "index" parameter
' is String, then FindItem will use the value as a Key. If integer, then Index.
' If no key or index is supplied, FindItem will start at the beginning of the
' list each time, which would be much slower than using a key.

' As long as I specify an integer for "index", FindItem work fine. When I specify
' a string key value, it gets run-time error 13 type mismatch. It's as though
' FindItem doesn't recognize that I'm supplying a string key, not an integer index.

Dim LI As ListItem
Dim W$

' object.Add(index, key, text, icon, smallIcon)
Set LI = ListView1.ListItems.Add(, "K111", "111")
Set LI = ListView1.ListItems.Add(, "K222", "222")
Set LI = ListView1.ListItems.Add(, "K333", "333")
W$ = ListView1.ListItems(2).Key ' Just checkin', Returns "K222"

' FindItem Method (ListView Control)

' Syntax: object.FindItem (string, value, index, match)
' object Required. An object expression that evaluates to a ListView control.
' string Required. A string expression indicating the ListItem object to be found.
' value Optional. An integer or constant specifying whether the string will be matched to
' the ListItem object's Text, Subitems, or Tag property, as described in Settings.
' index Optional. An integer or string that uniquely identifies a member of an object
' collection and specifies the location from which to begin the search. The integer
' is the value of the Index property; the string is the value of the Key property.
' If no index is specified, the default is 1.
' match Optional. An integer or constant specifying that a match will occur if the item's
' Text property is the same as the string, as described in Settings.

Set LI = ListView1.FindItem("222", lvwText, 1)      ' "index" is an integer (Start search at item #1). <==Works, returns "222"
Set LI = ListView1.FindItem("222", lvwText, 2)      ' "index" is an integer (start search at item #2). <==Works, returns "222"
Set LI = ListView1.FindItem("222", lvwText, 3)      ' "index" is an integer (start search at item #3). <==Fails, returns nothing

' Start search at item whose key property = "K222" Gets a Run-time error '13', type mismatch
Set LI = ListView1.FindItem("222", lvwText, "K222") ' "index" is a string Key. Start search at item whose key property = "K222"

Comments

  • StuckWithVB6StuckWithVB6 Little Rock, AR

    Sorry about the way this thing formatted. Any way to delete it and start over?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion