1

We have a classic ASP that uses a VB6 COM like this:

Dim Value1
Dim Value2
Dim Value3
'Etc.

Dim VB6COM
Set VB6COM = Server.CreateObject("VB6COM")
VB6COM.GetSomeValues MyConnectionString, "TABLE_NAME", "ROW_ID = 1", _
"FIELD_NAME_1", Value1, _
"FIELD_NAME_2", Value2, _
"FIELD_NAME_3", Value3, ... Etc.

The procedure being called is like this:

Public Sub GetSomeValues(ConnectionString, TableSource, SearchCondition, ParamArray Fields())

  'Code to open the database and retrieve the row goes here.
  'For this example to run without a database, we use example values below.

  For Index = 0 To UBound(Fields) Step 2
    Fields(Index + 1) = "ExampleValue" & Index
  Next

End Sub

We want to stop using the VB6COM and move this function to the ASP web site.

So the call should drop the Server.CreateObject lines and end up like this:

Dim Value1
Dim Value2
Dim Value3
'Etc.

GetSomeValues MyConnectionString, "TABLE_NAME", "ROW_ID = 1", _
"FIELD_NAME_1", Value1, _
"FIELD_NAME_2", Value2, _
"FIELD_NAME_3", Value3, ... Etc.

Problem is, VBScript does not support ParamArrays.

I know we can change the ParamArray to be an array object. But since we have to change thousands of calls, it would be better if there is a way to maintain the original call.

Any ideas?

Melipao
  • 31
  • 6

1 Answers1

1

You can use JScript in Classic ASP, which does support variable number of parameters, accessible via the arguments 'array'. I can't test it, but I believe you can include the 2 languages side-by-side and call functions defined in JScript from the VBScript.

<script language="JScript">
    // these parameters aren't used directly but they document the positions
    function GetSomeValues(connString, tableName, whereClause, columnName, value /* , ... */) {

        var args = arguments.slice(0), // make arguments a proper array
            ado = new ActiveXObject("ADODB.Connection"),
            connectionString = args.shift(),
            tableName = args.shift(),
            whereClause = args.shift(),
            columns = args; // rest of the arguments are your columns

        ado.ConnectionString = connectionString;
        /* etc */
    }
</script>
<script language="VBScript">
     GetSomeValues MyConnectionString, "TABLE_NAME", "ROW_ID = 1", _
        "FIELD_NAME_1", Value1, _
        "FIELD_NAME_2", Value2, _
        "FIELD_NAME_3", Value3, ... Etc.
</script>