Hallå i stugan! Längesedan man knåpade med VBScript.
Denna koden hade jag tänkt skulle bygga ihop en fin liten sql-sträng men det vill sig icke.
dim arrSQL()
If Len(Request.Form("XText")) = 1 then
ReDim arrSQL(0)
arrSQL(0) = "select P_ID_Products, P_Name from Products where P_Name like *"&Request.Form("XText")&"* "
End If
If Len(Request.Form("XPrice")) = 1 Then
If UBound(arrSQL) > 0 Then
ReDim Preserve arrSQL(UBound(arrSQL)+1)
UBound(arrSQL) = "and P_Price <"&Request.Form("intPrice") & " "
Else
ReDim arrSQL(0)
arrSQL(0) = "select P_ID_Products, P_Name from Products where P_Price <"&Request.Form("intPrice")
End If
End If
If Len(Request.Form("XCat")) = 1 Then
If UBound(arrSQL) > 0 Then
ReDim Preserve arrSQL(UBound(arrSQL)+1)
UBound(arrSQL) = "and P_ID_Category ="& Request.Form("strCat")
Else
ReDim arrSQL(0)
arrSQL(0) = "select P_ID_Products, P_Name from Products where P_ID_Category ="& Request.Form("strCat")
End If
End If
Response.Write LBound(arrSQL)
Subscript out of range: 'LBound'
Var har jag tänkt fel? :)
r) När jag kör denna koden är att åtminstone en av de tre if-satserna "true" - dvs. jag har kryssat för en eller flera checkrutor.
Funkar det kanske bättre såhär? (Fixade en annan sak också, som det var innan kunde du bara ha en post i arrayen)
intCount = 0
If Request.Form("XText") = "on" then
ReDim arrSQL(0)
arrSQL(0) = "select P_ID_Products, P_Name from Products where P_Name like *"&Request.Form("XText")&"* "
intCount = intCount + 1
End If
If Request.Form("XPrice") = "on" Then
If intCount > 0 Then
ReDim Preserve arrSQL(intCount)
arrSQL(intCount) = "and P_Price <"&Request.Form("intPrice") & " "
Else
ReDim arrSQL(0)
arrSQL(0) = "select P_ID_Products, P_Name from Products where P_Price <"&Request.Form("intPrice")
End If
intCount = intCount + 1
End If
If Request.Form("XCat") = "on" Then
If intCount > 0 Then
ReDim Preserve arrSQL(intCount)
arrSQL(intCount) = "and P_ID_Category ="& Request.Form("strCat")
Else
ReDim arrSQL(0)
arrSQL(0) = "select P_ID_Products, P_Name from Products where P_ID_Category ="& Request.Form("strCat")
End If
End If
Tack, men jag kom på att det var onödigt att använda en array så jag ändrade om det.
If Request.Form("XText") = "on" then
strSQL = "select P_ID_Products, P_Name from Products where P_Name like *"&Request.Form("XText")&"* "
End If
If Len(Request.Form("XPrice")) = 1 Then
If strSQL <> "" Then
strSQL = strSQL & "and P_Price <"&Request.Form("intPrice") & " "
Else
strSQL = "select P_ID_Products, P_Name from Products where P_Price <"&Request.Form("intPrice")
End If
End If
If Len(Request.Form("XCat")) = 1 Then
If strSQL <> "" Then
strSQL = strSQL & "and P_ID_Category ="& Request.Form("strCat")
Else
ReDim arrSQL(0)
strSQL = strSQL & "select P_ID_Products, P_Name from Products where P_ID_Category ="& Request.Form("strCat")
End If
End If
Dock verkar jag inte kunna kontrollera checkboxarna, varken med Request.Form("XText") = "on" eller Len(Request.Form("XPrice")) = 1
Jag förstår inte varför du blandar in en array i detta
dim arrSQL
If Len(Request.Form("XText")) > 0 then
arrSQL = "select P_ID_Products, P_Name from Products where P_Name like *"&Request.Form("XText")&"* "
End If
If Len(Request.Form("XPrice")) > 0 Then
if len(arrSQL) > 0 the
arrSQL = arrsql & " and P_Price <"&Request.Form("intPrice") & " "
Else
arrSQL = "select P_ID_Products, P_Name from Products where P_Price <"&Request.Form("intPrice")
End If
End If
If Len(Request.Form("XCat")) > 0 Then
If len(arrSQL) > 0 Then
arrSQL = arrsql & "and P_ID_Category ="& Request.Form("strCat")
else
arrSQL = "select P_ID_Products, P_Name from Products where P_ID_Category ="& Request.Form("strCat")
End If
End If
Response.Write arrSQL