Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile error: User-defined type not defined for "itmX As ListItem"

Status
Not open for further replies.

OMoore

Technical User
Oct 23, 2003
154
EU
Help!!!!

I'm putting together a dictionary of terms and keep getting a Compile error: User-defined type not defined for "itmX As ListItem". I have the microsoft scripting runtime library checked.

How do I get rid of this error?
My code is:

Private Sub Form_Load()

Dim dicX As Scripting.Dictionary
Dim varK As Variant
Dim varI As Variant
Dim lngX As Long
Dim itmX As ListItem
Set dicX = New Scripting.Dictionary
dicX.Add "A", "Athens"
dicX.Add "B", "Belgrade"
dicX.Add "C", "Cairo"

varK = dicX.Keys
varI = dicX.Items

For lngX = 0 To dicX.Count - 1
Set itmX = ListView1.ListItems.Add
With itmX
.Text = varI(lngX)
.SubItems(1) = varK(lngX)
End With
Next lngX

ListView1.AddItem.ListItem

End Sub

Owen
 
Have you actually added the Listview control to your form? The ListView control is in MSComCtl.OCX and you can add it to your project from Project|Components. When the ocx is added your ListItem should then be defined. I'm also not clear on what this line does:

ListView1.AddItem.ListItem

You should also read faq222-2244 as it gives guidance on how to get the best answers. It's usually best to keep continuation questions in the original thread so we can see where you've got to.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Thanks John.
I take your point about both threads - inexperience and over-eagerness!

(please ignore the ListView1.AddItem.ListItem line. I didn't mean for that to be pasted in)

The code is almost working correctly now. When I run it I get a runtime error 380, invalid property value for line:
.SubItems(1) = varK(lngX)

Apart from that it's almost good to go.

Thanks
Owen
 
The code works fine now. I deleted it and retyped and that seemed to work. Don't know why but it works!

Thanks
Owen
 
Should be OK as long as you have values for each Item and Key. Check that you have no blanks anywhere, and no duplicates in the Key collection

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top