locked
Warning 6 Variable is passed by reference before it has been assigned a value. A null reference exception could result at runtime. RRS feed

  • Question

  • User-1646638908 posted

     I totally understand why I am getting the error. However I want it to avoid the compile-time error.

    I can't figure out how to do it.  Is there a way to prevent it, there must be.

    Dim NamesArray() As String
    ' NamesArray passed by REFERENCE !
    Me.RemoveCommonWords(names, SlimName, NamesArray)
    

     

     

    Thanks in advance.

     

    Sunday, October 12, 2008 10:22 AM

Answers

  • User397347636 posted

    Set the variable to Nothing before calling the method.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 12, 2008 10:44 AM

All replies

  • User397347636 posted

    Set the variable to Nothing before calling the method.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 12, 2008 10:44 AM
  • User-1646638908 posted

    Woohoo !!! That did it... a problem since I started coding - really, believe to or else.

     

    Here is exactly how I avoid the compile time error:

     

    Dim NamesArray() As String  = Nothing

    Sunday, October 12, 2008 11:27 AM
  • User-1630302068 posted

     Warnings exist to point out common errors can lead to very subtle bugs.  A good rule is to always initialize your variables to /something/ even if it's the default values.

    Tuesday, October 14, 2008 11:29 AM