Discussions

Microsoft VBScript runtime (0x800A0009) Subscript out of range: '[number: 1

+
0 Votes
Locked

Microsoft VBScript runtime (0x800A0009) Subscript out of range: '[number: 1

dkale23
hi All,
I am getting the Following Error
Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '[number: 27]'
/www.iasp.ac.in/inc_register.asp, line 83


<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),"#") // //Error Line
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ","
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ","
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ","
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ", MEM_ACCESS) values (" & MM_dbValues & ", 'user')"

If (Not MM_abortEdit) Then
' execute the insert
Session("MM_Username") = Request.Form("MEM_NAME")
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
+
0 Votes
Tony Hopkinson

MM_Columns not having the same range as MM_Fields is the most likely candidate, could be MM_TypeArray which seems to be a mass of assumptions, but 27 makes that unlikely.

Personally I'd chnage this so you end up with some sort of name value and type construct, then iterate through that to build up the statement. You could build a parameterised query than and save youself another pile of grief, especially if datavalues comes from user input as that's a walking talking sql injection attack waiting to happen.