---
title: "array"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/91347-array"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "trexter"
published: "2003-11-26T16:12:00.000Z"
updated: "2003-11-26T16:44:22.000Z"
replies: 5
views: 230
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/91347-array"
---

# array

## #1 — trexter, 2003-11-26T16:12Z

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.

Permalänk: https://www.webforum.nu/p/91347

## #2 — Sebbe, 2003-11-26T16:33Z

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
```

Permalänk: https://www.webforum.nu/p/1214266

## #3 — trexter, 2003-11-26T16:37Z

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

Permalänk: https://www.webforum.nu/p/1214272

## #4 — Sebbe, 2003-11-26T16:39Z

Går det kanske med Request.Form("XText") \<\> "" då?

Permalänk: https://www.webforum.nu/p/1214274

## #5 — LarsG, 2003-11-26T16:39Z

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.

Permalänk: https://www.webforum.nu/p/1214276

## #6 — trexter, 2003-11-26T16:44Z

> **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å. ;)

Permalänk: https://www.webforum.nu/p/1214278

---

Tråden på webben: https://www.webforum.nu/amne/asp/91347-array
