How to create an empty Double array

I am trying to create an empty / specific array Double

that will display as Double(0, -1)

.

I can create it for an array String

, Variant

and Byte

:

  Dim arr_variant() As Variant
  arr_variant = Array()        ' Variant(0 to -1) '

  Dim arr_string() As String
  arr_string = Split(Empty)    ' String(0 to -1) '

  Dim arr_byte() As Byte
  arr_byte = ""                ' Byte(0 to -1) '

  Dim arr_double() As Double
  arr_double = ???             ' Double(0 to -1) '

      

but still haven't found a way for Double

.

Maybe with LSet

or with a native function?

+3


source to share


2 answers


It seems like the only way is to call the native function:



Private Declare PtrSafe Function SafeArrayRedim Lib "OleAut32" ( _
  ByVal arr As LongPtr, ByRef dims As Any) As Long


Public Sub RedimDouble(arr() As Double, ByVal count As Long)
  If count Then
    ReDim Preserve arr(0 To count - 1)
  Else
    ReDim arr(0 To 0)
    SafeArrayRedim Not Not arr, 0@
  End If
End Sub


Public Sub Usage()

  Dim arr_double() As Double
  RedimDouble arr_double, 0    ' Double(0 to -1) '

End Sub

      

+2


source


I would have gone - failed .

Take a look at the following code:

Option Explicit
Sub TestMe()
    Dim arr                   'Line 1
    arr = Array(CDbl(0))      'Line 2
    arr = Array(Empty)        'Line 3
End Sub

      

  • Line 1 - Requires array Variant

enter image description here



  • Line 2 - Make a double array

enter image description here

  • Line 3 - When emptied, it is converted from double to variant again.

enter image description here

+1


source







All Articles