Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Subroutine

Status
Not open for further replies.

RushiShroff

Programmer
Jan 23, 2002
216
IN
Here is the code for generating a string for site SEArch.
Here this is to be included in an ASP page.

My problem is I can not access temp2 variable which is a string outside of search subroutine.
what to do ?



<%
'response.write Keywords
Dim strParse,criteria,searchstring,searchchar,findplus,findspace
Dim plusArray, blankArray, mCategory, mSubCategory, rstPrime_Category
searchchar=&quot;+&quot;
searchstring=Keywords
searchstring=Replace(searchstring,&quot;&quot;&quot;&quot;,&quot;#&quot;)
If Left(searchstring,1)=&quot;#&quot; and Right(searchstring,1)=&quot;#&quot; then
searchstring=Replace(searchstring,&quot;#&quot;,&quot;&quot;)
End If

findplus=instr(1,searchstring,searchchar)

if findplus >= 1 then
criteria=&quot;AND&quot;
' get every element into array separated by &quot;+&quot;
plusArray=split(searchstring,searchchar)
redim preserve plusArray(Ubound(plusArray)+1)

for i=0 to Ubound(plusArray)-1
'check for &quot; , ,
'1.check for &quot;&quot;&quot;
searchchar=&quot;&quot;&quot;&quot;
searchstring=plusArray(i)
findquote=instr(1,searchstring,searchchar)

if findquote >=1 then
plusArray(i)=replace(plusArray(i),&quot;&quot;&quot;&quot;,&quot; &quot;)

'remove the spaces at both ends
plusArray(i)=rtrim(ltrim(plusArray(i)))
end if

'2.check for &quot;,&quot;
searchchar=&quot;,&quot;
searchstring=plusArray(i)
findcomma=instr(1,searchstring,searchchar)
if findcomma>1 then
plusArray(i)=rtrim(ltrim(replace(plusArray(i),&quot;,&quot;,&quot; &quot;)))
end if
next
'pass all the array values to procedure
call search(plusArray,criteria)
else
'check whether &quot; &quot; present
searchchar=&quot;&quot;&quot;&quot;
searchstring=Trim(Request.Form(&quot;T_searchfor&quot;))
searchstring=Replace(searchstring,&quot;&quot;&quot;&quot;,&quot;#&quot;)
If Left(searchstring,1)=&quot;#&quot; and Right(searchstring,1)=&quot;#&quot; then
searchstring=Replace(searchstring,&quot;#&quot;,&quot;&quot;)
End If
findquotes=instr(1,searchstring,searchchar)

if findquotes>=1 then
'check whether , present

searchchar=&quot;,&quot;
findcomma=instr(1,searchstring,searchchar)

if findcomma>=1 then
criteria=&quot;OR&quot;
else
criteria=&quot;AND&quot;
end if
blankArray=Array(searchstring)
call search(blankArray,criteria)
else
criteria=&quot;OR&quot;

'check for spaces
searchchar=&quot; &quot;
findspaces=instr(1,searchstring,searchchar)

if findspaces>=1 then
spacesArray=split(searchstring,searchchar)

'Trim individual array element
for i=0 to UBound(spacesArray)
spacesArray(i)=trim(spacesArray(i))
next
'if any array element is blank or has space removed it
for i=0 to UBound(spacesArray)
if spacesArray(i)=&quot; &quot; then
'track this element
flag=i
for k=flag+1 to UBound(spacesArray)
'backup_spacesArray(i)=spacesArray(i)
spacesArray(k-1)=spacesArray(k)
next
redim preserve spacesArray(Ubound(spacesArray))
else
redim preserve spacesArray(Ubound(spacesArray)+1)
end if
next

call search(spacesArray,criteria)
'pass the array to the search
'input parameters
else
'convert the string to array
blankArray=Array(searchstring)
call search(blankArray,criteria)
end if
end if
end if
response.write temp2'Can not access it here
%>
<%
Sub search(ByVal arr(),criteria)
Dim pad,arr_Size, loop_ctr
arr_Size = Ubound (arr)
for i=0 to arr_size
if arr(i) = &quot;&quot; then
loop_ctr = i
exit for
end if
Next

if Ubound (arr) = 0 then
temp2= &quot;Keywords LIKE '%&quot;
temp2=temp2&arr(0)
temp2=temp2&&quot;%'&quot;
else
For i = 0 to arr_size
If arr(i) = &quot;&quot; then
exit for
end if
temp2= temp2 & &quot;Keywords LIKE '%&quot; & arr(i) & &quot;%'&quot;
'response.write temp2&&quot;<br>&quot;
If i < (loop_ctr-1) then
temp2 = temp2 & &quot; &quot; & criteria & &quot; &quot;
end if
Next
End if
End Sub
%>


Rushi Shroff Rushi@emqube.com
&quot;Life is beautiful.&quot;
 
I think this is the same problem as your other post.
The scope of the variable temp2 is limited to the search(0 subroutine.

Try declaring temp2 in the code above the subroutine, before the subroutine is called.

See your other post for a similar example. (If I am right!)

bp
 
Please pardon my earlier typo.

bad: is limited to the search(0 subroutine

good: is limited to the search() subroutine

sorry about that.
bperry
 
thanks bperry Rushi Shroff Rushi@emqube.com
&quot;Life is beautiful.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top