The following codes return error "invalid property array index"

If OpenRegistry = true then
Dim strKeyValue as string
Dim J as Integer
for J = 0 to frmRega.lstRegEntries.ListCount - 1
If frmRega.lstRegEntries.Selected(J) = true then
strKeyValue = Trim$(Str(J))
lngReturnValues = RegDeleteValue(hKey, byval strKeyValue)
If lngReturnValues = ERROR_SUCCESS then
frmRega.lstRegEntries.RemoveItem (J)
MsgBox "success!"
End If
End If
next J
End If



The item is deleted but error occurs when the integer J is equal to
the ListCount.

Thanks,
Simon