2016-05-10 10 views
1

私は古典的なASPの文字列検索用のコードを書いていますが、エラーが表示されます。例えば 検索エラーが発生する "下付き文字範囲外のエラー" aspの古典

my name is lucky from earth 

に書き込みされている場合、私は

のMicrosoft VBScriptランタイムエラー範囲のうち '800a0009'
添字このエラーが出ます: '6'
/bdn6/prod_search.asp

線68は、ライン68

SWord = SWord & " " & Trim(arrKeyWords(j)) 

は私のコードは以下のように与えられる:

<% 
Dim SearchWord, arrKeyWords, arrQry, MainQty, FinalQty, MergeQry, WhereCon, Cnt, tsearch, i, j 
SearchWord = trim(request("searcha")) 
arrKeyWords = Split(SearchWord ," ") 
Cnt = Ubound(arrKeyWords) + 1 
%> 

<% 
dim Qry, SWord, NLWord, TableName, LastIndex 
MainQty = "select a.rProd_name, r_id " 
TableName = "from reseller_prod a, brand e, V_brand f, V_modal g Where a.rprod_vbrand=f.Vb_Id and f.vb_active=0 and a.rprod_vmodel=g.Vm_id and g.Vm_active=0 and a.rProd_brand=e.Brand_id and e.brand_active=0 and a.rProd_price <> 0 and a.rProd_price is not Null and a.rprod_nowallowd=0 and a.r_id in(select s_usrid from Reseller where S_approval=0) and a.r_id in(select usr_id from usr where Usr_Active=0)" 
NLWord = "" 
For i = 0 To Cnt 
SWord = "" 
For j = 0 To ((Cnt) - i) 

SWord = SWord & " " & Trim(arrKeyWords(j)) 'getting error on this line: Subscript out of range 

Next 
WhereCon = WhereCon & " And (a.rProd_name like '%" & Trim(SWord) & "%' or f.vb_name like '%" & Trim(SWord) & "%' or g.Vm_modal like '%" & Trim(SWord) & "%')" 
Qry = MainQty & ", " & (i + 1) & " as SortRecord " & TableName & " " & WhereCon 
LastIndex = i + 1 
Qry = Qry & NLWord 
NLWord = NLWord & " And (a.rProd_name not like '%" & Trim(SWord) & "%' And f.vb_name not like '%" & Trim(SWord) & "%' And g.Vm_modal not like '%" & Trim(SWord) & "%')" 
FinalQty = FinalQty & Qry & " UNION " 

WhereCon = "" 
Qry = "" 

Next 

FinalQty = left(FinalQty, (Len(FinalQty) - 6)) 

MergeQry = FinalQty 
FinalQty = "" 

MainQty = "select a.Prod_name, '' as r_id " 
TableName = "from product a, brand e, V_brand f, V_modal g Where a.prod_vbrand=f.Vb_Id and f.vb_active=0 and a.prod_vmodel=g.Vm_id and g.Vm_active=0 and a.Prod_brand=e.Brand_id and e.brand_active=0 and a.prod_active=0 and a.Prod_price <> 0 and a.Prod_price is not Null" 

NLWord = "" 
For i = 0 To Cnt 

SWord = "" 
For j = 0 To ((Cnt) - i) 

SWord = SWord & " " & Trim(arrKeyWords(j)) 
Next 
WhereCon = WhereCon & " And (a.Prod_name like '%" & Trim(SWord) & "%' or a.prod_keyword like '%" & Trim(SWord) & "%' or f.vb_name like '%" & Trim(SWord) & "%' or g.Vm_modal like '%" & Trim(SWord) & "%')" 
Qry = MainQty & ", " & (LastIndex + i + 1) & " as SortRecord " & TableName & " " & WhereCon 
Qry = Qry & NLWord 
NLWord = NLWord & " And (a.Prod_name not like '%" & Trim(SWord) & "%' and a.prod_keyword not like '%" & Trim(SWord) & "%' And f.vb_name not like '%" & Trim(SWord) & "%' And g.Vm_modal not like '%" & Trim(SWord) & "%')" 
FinalQty = FinalQty & Qry & " UNION " 

WhereCon = "" 
Qry = "" 

Next 
FinalQty = left(FinalQty, (Len(FinalQty) - 6)) 
FinalQty = FinalQty & "Order By SortRecord" 

MergeQry = MergeQry & " UNION " & FinalQty 

response.Write(MergeQry) 
%> 

は、この問題を解決するために私を助けてください。

答えて

1

読み取り何か約Array Variables:括弧内に示す番号が10あるが

Dim A(10) 

、 VBScriptで全て配列はゼロベースであるので、この配列は、実際に11 要素を含みます。ゼロベースの配列では、配列要素の数は常に であり、常にカッコで示された数に1を加えたものです。この種の配列は、固定サイズ配列と呼ばれる です。

Split Function

ストリングの指定 数を含むゼロベース、一次元アレイを返します。

UBound Function

アレイの示された寸法のために最大使用可能添字を返します。

したがって

Cnt = Ubound(arrKeyWords) ''' instead of Cnt = Ubound(arrKeyWords) + 1 

又は(Cnt = Ubound(arrKeyWords) + 1時主張)

For i = 0 To Ubound(arrKeyWords) 
    SWord = "" 
    For j = 0 To (Ubound(arrKeyWords) - i) 
     SWord = SWord & " " & Trim(arrKeyWords(j)) 
    Next 
    ''' … ''' 
Next 

又は(Cnt = Ubound(arrKeyWords) + 1時主張)のいずれかを使用

For i = 0 To cnt -1 
    SWord = "" 
    For j = 0 To (cnt - 1 - i) 
     SWord = SWord & " " & Trim(arrKeyWords(j)) 
    Next 
    ''' … ''' 
Next 
関連する問題