Home Type mismatch: array or user-defined type expected, trying to pass array to a sub
Reply: 0

Type mismatch: array or user-defined type expected, trying to pass array to a sub

user1382
1#
user1382 Published in April 24, 2018, 8:25 am

I have an array and a displayArray sub which I try to use. However, I get a

Type mismatch: array or user-defined type expected error

Main sub:

Dim someArray() As Double
someArray = getBinsArray(sumLossesColl)
displayArray (someArray)

displayArray sub:

Sub displayArray(someArray() As Double)
    Dim i As Long


    With ThisWorkbook.Worksheets("Sheet1")
        .Range(.Cells(1, 1), .Cells(1, UBound(someArray) - LBound(someArray))).value = someArray
    End With
End Sub

'getBinsArray' function:

Function getBinsArray(dataArray() As Double)
    Dim binsNumber As Long
    Dim binSize As Double

    binsNumber = Round(VBA.Sqr(UBound(dataArray) - LBound(dataArray)) + 0.5)
    MsgBox ("binsNumber: " & binsNumber)

    binSize = (getMaxValue(dataArray) - getMinValue(dataArray)) / (binsNumber - 1)

    Dim resultArray() As Double
    ReDim resultArray(1 To bindsNumber) As Double
    resultArray(1) = getMinValue(dataArray)

    Dim i As Long
    For i = 2 To binsNumber
        resultArray(i) = resultArray(i - 1) + binSize
    Next


    getBinsArray = resultArray
End Function

What is the reason behind this? The types are Double, everything seems fine. How to fix it?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.352274 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO