Hi,
Can anyone explain why my code enters a loop when the length of a file is zero. I would expect that the loop below would not be entered if strFile.Length is zero.

strFile = strSubCommittees.Split("|")
For i = 0 To strFile.Length - 1

Next i

Thanks.

if  strFile.Length <> 0
'Code
end if

Yes. I thought of that but I wouldn't of thought you had to as it shouldn't enter the loop if the length is zero. Anyway, thanks for your reply, I guess I'll have to add the extra code.
Thanks.

Your array is not actually zero length, it has a length of one!

strFile is an array. The array can either be "nothing" or have at least one element to it; even if it is blank.
strFile = strSubCommittees.Split("|")
This will automatically assign at least one element to your array, even if it is blank and doesnt actually have a value in that element.

Try this in a console app to see the results:

Sub Main()

        Dim strCommittees As String = ""
        Dim strFile() As String = Nothing

        If strFile Is Nothing Then
            Console.WriteLine("strFile() is nothing")
        Else
            Console.WriteLine("strFile.Length : {0}", strFile.Length)
        End If

        Console.WriteLine("'Read blank value into array")
        Console.WriteLine("strCommittees.Split(""|""c)")

        strFile = strCommittees.Split("|"c)
        Console.WriteLine("strFile.Length : {0}", strFile.Length)

        Console.ReadLine()

    End Sub

You're right. Thanks for your reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.