Declare a 0-Length String Array in VBA - Impossible?

前端 未结 3 514
旧巷少年郎
旧巷少年郎 2021-01-12 21:31

Is it really not possible to declare a 0-length array in VBA? If I try this:

Dim lStringArr(-1) As String

I get a compile error saying rang

3条回答
  •  心在旅途
    2021-01-12 21:56

    Per Comintern's comment.

    Make a dedicated utility function that returns the result of the VBA.Strings.Split function, working off vbNullString, which is effectively a null string pointer, which makes the intent more explicit than using an empty string literal "", which would also work:

    Public Function EmptyStringArray() As String()
         EmptyStringArray = VBA.Strings.Split(vbNullString)
    End Function
    

    Now branch your function to check for the existence of keys, and return EmptyStringArray if there are none, otherwise proceed to resize your result array and convert each source element.

提交回复
热议问题