A.Wad
A.Wad

Reputation: 29

Argument "Index" is not a valid value

I am developing a tool to commit dcm files and now I have a bug that refuse to commit removed files when they had been used as a source file for other added files.

Procedure :

1- Copy file called FILE_A and name it as FILE_B and implement some changes to the parameters in FILE_B then commit changes using the tool( with choosing FILE_A as a reference file ) .. works totally fine.

2- Delete FILE_A and keep FILE_B and then use the tool to commit .. tool will crash and be closed.

And here is the lines that throw the exception and close the tool :

If FilesGrid.Item(0, a).Value = True And FilesGrid.Item(2, a).Value.ToString() = "Removed" Then

    FilesRemoved.Add(FileLocalPos.Item(FilesGrid.Item(1, a).Value.ToString))
    myFileVector.Add(FileLocalPos.Item(FilesGrid.Item(1, a).Value.ToString))

End If

The exception message is :

Argument "index" is not a valid value

Your help is highly appreciated ..

Upvotes: 1

Views: 5948

Answers (2)

philu
philu

Reputation: 874

This message means the Collection does not contain the item you tried to locate using the Item function.

To prevent this message, use the Contains method before trying to reference the Item. E.g.

If FilesGrid.Contains(0, a) and FilesGrid.Contains(2, 1) Then
    If FilesGrid.Item(0, a).Value = True And FilesGrid.Item(2, a).Value.ToString() = "Removed" Then

Upvotes: 0

JDB
JDB

Reputation: 25810

Just a guess:

Save FilesGrid.Item(1, a).Value.ToString to a variable:

If FilesGrid.Item(0, a).Value = True And FilesGrid.Item(2, a).Value.ToString() = "Removed" Then
    Dim l_itemIndex = FilesGrid.Item(1, a).Value.ToString

    FilesRemoved.Add(FileLocalPos.Item(l_itemIndex))
    myFileVector.Add(FileLocalPos.Item(l_itemIndex))
End If

Upvotes: 1

Related Questions