trexterMedlem sedan mars 20021 424 inlägg
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.
SebbeMedlem sedan jan. 20031 603 inlägg
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
trexterMedlem sedan mars 20021 424 inlägg
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
SebbeMedlem sedan jan. 20031 603 inlägg
Går det kanske med Request.Form("XText") <> "" då?
LarsGMedlem sedan dec. 200012 465 inlägg
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
ed: Ok, det var sent.
trexterMedlem sedan mars 20021 424 inlägg
Sebbe skrev:
Går det kanske med Request.Form("XText") <> "" då?
Tack! Probelemet löst! Och LarsG: Helt rätt... vet inte vad jag tänkte på. ;)