Dim stringIdCollection
    stringIdCollection = Join( Request.Form( "id" ), "', '" ) )    
Dim whereStatement
    whereStatement = "WHERE id IN ('" & stringIdCollection & "');"

I get this error:

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/includes/Process.asp, line 49 stringIdCollection = Join( Request.Form( "id" ), "', '" ) ) ------------------------------------------------------------------------^

Is it even possible to use Join on a Request.Form?

I would like the output to be:

"WHERE id IN ('122', '344', '599')"

有帮助吗?

解决方案

The join function expects an array as the first parameter. In Classic ASP (VBScript) the data in Request.Form is always string, so impossible to have an actual array in it, you have to build the array yourself :

Dim myArray
myArray = Array(Request.Form("id"), Request.Form("id2"), Request.Form("id3"))

Dim stringIdCollection
stringIdCollection = Join( myArray , "', '" ) ) 

Also notice that in Classic ASP, if you submit multiple form fields with the same names (i.e. id), they will get in Request.Form already separated by a commas.

Contrary to what can be done in PHP, naming multiple form fields with square brackets [] appended at the end, ASP will not convert it as an array in Request.Form.

其他提示

That looks like an extra parentheses on the second line that should be deleted:

    stringIdCollection = Join( Request.Form( "id" ), "', '" )

EDIT: The documentation for Request.Form is a little bit misleading. The value returned by Request.Form("item") isn't really an array, but an array-like object. You can iterate through those values by using the Count property and build your string as you iterate:

Dim stringIdCollection, i

For i = 1 To Request.Form("id").Count
    If Len(stringIdCollection) <> 0 Then
        stringIdCollection = stringIdCollection & ","
    End If
    stringIdCollection = stringIdCollection & "'" & Request.Form("id")(i) & "'"
Next
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top