0

I have a short app that check if my music files are names to a specific routine (track number and then track name), but I'm getting an error whenever there are no files that need renaming, because the array in initialised, but the first item is nothing, null, empty (however VB refers to it).

To try and fix this, I'm running this check, but I'm still getting an error.

    ' Array declared like this
    Dim nc_full_names(0) As String

    <Code goes here to ReDim 'nc_full_names' and add the file name to the array, if a file needs renaming>

    For i = 0 To UBound(nc_full_names)

            'Checking if the array element actually has something in it like this
            If Not nc_full_names Is Nothing Then
                    My.Computer.FileSystem.RenameFile(nc_full_names(i), nc_new_names(i))
            Else
                    Exit For
            End If

    Next i

Here is the error that I am getting -

Argument cannont be nothing. Parameter name: file

Can anyone tell me the correct way to carry out this check?

2 Answers 2

2

I found that the answer was to check the first element in the array, as opposed the array itself. Thus, changing this...

    If Not nc_full_names Is Nothing Then

...to this...

    If Not nc_full_names(i) Is Nothing Then

...works just fine.

Sign up to request clarification or add additional context in comments.

1 Comment

That will throw an error if nc_full_names(i) is nothing. .NET is going to evauate nc_full_names(i) before it applies any other logic.
0

You can also start with a truly empty array:

Dim nc_full_names(-1) As String

Now nc_full_names.Length = 0.

1 Comment

Thanks for the Tip @MarkHurd, I'll remember that for next time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.