Find how many actual entries are in a Visual Basic string array

(c) 2017 by Barton Paul Levenson


Language:
Basic

Dialect:
Microsoft Visual Basic Express 2010

Discussion:
the method .Length only tells you the declared length of an array. To find how many entries are actually sitting there with some value in them, this short routine gives the answer. All you need is not to count the empty strings.


    ' arrTrueLen gives the actual number of entries in a string
    ' array.
    Function arrTrueLen(s() As String) As Integer
        Dim trueLen As Integer = 0

        For Each st As String In s
            If st <> "" Then
                trueLen += 1
            End If
        Next

        arrTrueLen = trueLen
    End Function ' arrTrueLen


Page created:08/20/2017
Last modified:  08/20/2017
Author:BPL