PDA

View Full Version : Problem with IN statement


dominicall
03-11-2003, 05:07 PM
OK - anyone help me out here???

Am creating an array from checkboxes in a form input (let's call it interests2) - that looks like this ('1','4','5','6')

If there are errors in the form then I want to keep the checked status so am trying this....
While Not rsActivities.EOF
If rsActivities("ActivityID") IN (interests2) Then
checkedstatus = " checked"
Else
checkstatus = ""
End If
......
Wend
which I thought would be fine... but it's not working - grrrr....

The error message I'm being presented with is...

Error in Microsoft VBScript compilation . Code: -2146827271 (0x800A03F9) Expected 'Then'. Line 204, column 30 If rsActivities("ActivityID") IN (interests2) Then

Now I can only assume it's something to do with the commas in the array but can't seem to figure it...

Anyone got any ideas???

Thanks

dominicall :confused:

arnyinc
03-11-2003, 08:22 PM
I don't use ASP all the time, but I've never seen an if statement with "IN". You might need to make a loop and compare everything in the array to the activityid individually.

oracleguy
03-11-2003, 08:36 PM
Is the "ActivityID" field one of the index numbers in the array?

If so it should be:

While Not rsActivities.EOF
If interests2(rsActivities("ActivityID")) Then
checkedstatus = " checked"
Else
checkstatus = ""
End If
......
Wend

dominicall
03-11-2003, 09:08 PM
OK - tried Oracleguy's approach - at least now I don't get the CVscript comilation error...

now the problem is typemismatch - code is as follows:
If formaction <> "" Then
If interests2(rsActivities("ActivityID")) Then
checkedstatus = " checked"
Else
checkstatus = ""
End If
End If
Given that the interests2 array is something like ('1','3','4','6') and the ActivityID is an integer then I've tried using CStr on the ActivityID but still gives a type mismatch...

Have also tried it with an array without the single-quotes, i.e. (1,3,4,5,6) - but still get the type mismatch.

Any ideas???

dominic :confused:

dominicall
03-11-2003, 09:28 PM
It's amazing how dumb I can be sometimes - LOL.... a lesson in spending too long looking for the complicate solution....

Here's the working perfectly solution that popped into my head whilst watching the football...
Dim actCol, checkedstatus, checkstring
interests2 = CStr(interests2)
checkedstatus = ""

actCol = 1
While Not rsActivities.EOF
If formaction <> "" Then
checkstring = "'" & CStr(rsActivities("ActivityID")) & "'"
If InStr(interests2,checkstring) Then
checkedstatus = " checked"
Else
checkedstatus = ""
End If
End If
A simple InStr call - oops.

dominicall :o