title: VB6 - Passing an Array as the ParamArray argument of a function
body: <p>We have this utility method in a VB6 COM library for executing parameterised SQL:</p>
  
  <pre><code>Public Sub ExecSQL(ByVal strSQL As String, ParamArray varParams() As Variant)
      'snip - ADODB data access
  End Sub
  </code></pre>
  
  <p>Where varParams is a two dimensional array of SQL parameter information. Example usage would be:</p>
  
  <pre><code>ExecSQL("SELECT * FROM People WHERE Name = ?", Array("@p1", adVarChar, 10, "Smith"))
  </code></pre>
  
  <p>This is tried and tested code and works fine in normal usage. I am now in an unusual situation where the SQL string is a configurable value and could contain any number of parameters, so what I need to do is pass an unknown number of arguments in to the ParamArray. My attempt so far (simplified) is:</p>
  
  <pre><code>Function ExecConfigurableSql(sqlString As String, parameterValues() As String)
  
      Dim parameters() As Variant
      ReDim parameters(UBound(parameterValues)) As Variant
  
      For i = 0 To UBound(parameterValues)
          parameters(i) = Array("@p" + CStr(i), adVarChar, 1000, parameterValues(i))
      Next
  
      ExecSQL(sqlString, parameters) 'Type Mismatch
  End Function
  </code></pre>
  
  <p>The attempt to execute the SQL throws a Type Mismatch error. Is there a way to pass an Array in to a function which expects a ParamArray? Or am I making an altogether separate mistake somewhere?</p>
  
  <p>This is what the parameters look like with a dynamically built up array:</p>
  
  <p><img src="https://i.stack.imgur.com/kbm7Q.png" alt="Dynamic array">
  And this is what they look like when passed with comma-separated ParamArray syntax (which works):</p>
  
  <p><img src="https://i.stack.imgur.com/6QaFW.png" alt="ParamArray"></p>
  
  <p>The structure looks the same to me.</p>