我们有一个使用VB6 COM的经典ASP:
<div class="field-group">
<label for="textinput">Text Input:</label>
<input type="text" id="textinput" />
</div>
调用的过程如下:
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.
我们想停止使用VB6COM并将此功能移至ASP网站。
因此调用应该删除Server.CreateObject行并最终结束:
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
问题是,VBScript不支持ParamArrays。
我知道我们可以将ParamArray更改为数组对象。但是,由于我们必须改变数千个电话,如果有办法维持原始电话会更好。
有什么想法吗?
答案 0 :(得分:0)
您可以在Classic ASP中使用JScript,它支持可变数量的参数,可通过arguments
'数组'访问。我无法测试它,但我相信你可以并排包含2种语言,并从VBScript中调用JScript中定义的函数。
<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>