Array argument must be ByRef

前端 未结 1 1369
梦如初夏
梦如初夏 2020-12-07 04:23

What am I doing wrong here?

Sub Main()

Dim patients() As String

\' Some code to populate the patients array, works fine

CalculateScores (patients) \' Arra         


        
相关标签:
1条回答
  • 2020-12-07 04:57

    When you do this:

    DoSomething (expression)
    

    You're forcing expression to be evaluated as a value, and passed ByVal, regardless of whether the parameter explicitly says it's passed ByRef. While that has more or less no impact most of the time, it bites you in the rear end when you try to pass an array or an object reference.

    Drop the parentheses.

    DoSomething expression
    

    Now, there are other problems with your code: You're passing an array of strings into a String parameter; that can't work. Make the parameter an array or a Variant, and I'd suggest marking the parameter explicitly as ByRef, for clarity.

    0 讨论(0)
提交回复
热议问题