Avatar of XK8ER
XK8ERFlag for United States of America

asked on 

error on code

hello there,
when I try to remove duplicates from a listview with more than 3k records in it.. I get an error

run time error 35600
index out of bound

the line bellow with >> is the one that gets yellow
Dim lRet As ListItem, strTemp As String, intCnt As Integer
    intCnt = 0
    
    Do While intCnt <= lvwMain.ListItems.Count - 1
        intCnt = intCnt + 1
        strTemp = lvwMain.ListItems.Item(intCnt).SubItem(1)
        Do
>>          lvwMain.ListItems.Item(intCnt).SubItems(1) = ""          
            Set lRet = lvwMain.FindItem(strTemp, lvwSubitem)
            
            If Not lRet Is Nothing Then
                lvwMain.ListItems.Remove (lRet.Index)
            End If
 
        Loop While Not lRet Is Nothing
        
        lvwMain.ListItems.Item(intCnt).SubItem(1) = strTemp
        DoEvents            
    Loop

Open in new window

Visual Basic Classic

Avatar of undefined
Last Comment
game-master
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try put intCnt = intCnt + 1 on bottom before the "loop":
Dim lRet As ListItem, strTemp As String, intCnt As Integer
    intCnt = 0
    
    Do While intCnt <= lvwMain.ListItems.Count - 1
        
        strTemp = lvwMain.ListItems.Item(intCnt).SubItem(1)
        Do
          lvwMain.ListItems.Item(intCnt).SubItems(1) = ""          
            Set lRet = lvwMain.FindItem(strTemp, lvwSubitem)
            
            If Not lRet Is Nothing Then
                lvwMain.ListItems.Remove (lRet.Index)
            End If
 
        Loop While Not lRet Is Nothing
        
        lvwMain.ListItems.Item(intCnt).SubItem(1) = strTemp
 
intCnt = intCnt + 1
 
        DoEvents            
    Loop

Open in new window

Avatar of XK8ER
XK8ER
Flag of United States of America image

ASKER

now with your code I get an error in the first strTemp = lvwMain.ListItems.Item(intCnt).SubItems
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try change:

strTemp = lvwMain.ListItems.Item(intCnt).SubItem(1)


to:

strTemp = lvwMain.ListItems.Item(intCnt).SubItems(1)
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of XK8ER
XK8ER
Flag of United States of America image

ASKER

this is what I have so far.. and it works pefectly fine with about 500 records then when I import 4k I get an error in the >> marked line
Private Sub RemoveDups(strNum As Integer)
    Dim lRet As ListItem, strTemp As String, intCnt As Long
    intCnt = 1
    
    Do While intCnt <= lvwMain.ListItems.Count
        strTemp = lvwMain.ListItems.Item(intCnt).SubItems(strNum)
        Do
>>            lvwMain.ListItems.Item(intCnt).SubItems(strNum) = ""
            Set lRet = lvwMain.FindItem(strTemp, lvwSubItem)
    
            If Not lRet Is Nothing Then
                lvwMain.ListItems.Remove (lRet.Index)
            End If
        Loop While Not lRet Is Nothing
        
        lvwMain.ListItems.Item(intCnt).SubItems(strNum) = strTemp
        intCnt = intCnt + 1
        DoEvents
    Loop
End Sub

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

>>and it works pefectly fine with about 500 records then when I import 4k I get an error in the >> marked line

so what is the value of "strNum" here?
Avatar of XK8ER
XK8ER
Flag of United States of America image

ASKER

im using it like this

Call RemoveDups(1)
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

seems run fine for me, what error message you get here?
Avatar of XK8ER
XK8ER
Flag of United States of America image

ASKER

this error

run time error 35600
index out of bound
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Check this out on possibly to resolve error "run time error 35600 index out of bound":
http://support.microsoft.com/kb/q167122/
Avatar of game-master
game-master
Flag of Philippines image

good afternoon!
yes u will receive that kind of error because, ineteger holds the listcount of the listview and when
you remove the duplicate, the integer still holds the initial listcount..
that is why i add "On error resume next on the code"...

I''ve pasted this code earlier on your question, unfornatunately you accepted another comments..lol..
anyway try this code...


On Error Resume Next
Dim lRet As ListItem, strTemp As String, intCnt As Integer
    intCnt = 0
   
    Do While intCnt <= lsvWork.ListItems.Count - 1
        intCnt = intCnt + 1
        strTemp = lsvWork.ListItems.Item(intCnt).SubItems(1)
        Do
            Set lRet = lsvWork.FindItem(strTemp, lvwSubItem, intCnt + 1, 0)
           
            If Not lRet Is Nothing Then
                lsvWork.ListItems.Remove (lRet.Index)
            End If
 
        Loop While Not lRet Is Nothing
       
        DoEvents
        Loop


i tried it and it works fine with me..


game-master
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo