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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting to ASP code.

Status
Not open for further replies.

taval

Programmer
Jul 19, 2000
192
GB
I have this piece of pseudocode that I wish to convert to asp:

--------------------------------------------------

<<< pointer to increment array >>>
arrayinc=0
dim extarray(50)


While not rsFiles.EOF


<<< finds the file extension >>>
file = rsFiles(&quot;FileName&quot;)
rtn = InStr(1,file, &quot;.&quot;)
if rtn > 0 then
extension = Right(file, (Len(file)-rtn+1))
end if


for l=1 to howmanyrecs
<<< if extension tyoe already in array then exit loop >>>
if extArray(l) = extension then
exit-loop <<< code to exit the loop >>>
else
<<< otherwise add extension to array >>>
arrayinc= arrayinc+1
extArray(arrayinc)= extension
exit-loop <<< code to exit the loop >>>
end if
next l

rsFiles.MoveNext


wend

--------------------------------------------------

could someone plz correct it and add the code that will exit the loop. The codes meant to check if a string called &quot;extension&quot; is in the array, if it is it should break out of the loop otherwise it should add the string to the array.

Grateful for any help, Thanks.
 
hmmm, as long as we're doing your work, do you mind sharing your paycheck?
 
usually to get out of a loop in VBscript you do a &quot;exit looptype&quot; statement. Thus if it's a for loop you do:

if whatever = whatever then exit for end if
 
dear geewiz,
I don't get payed for what I do, I do this programming as a hobbie and to help other people who need small programs.
 
Taval,
here's the code which does the same thing as we discussed in your other post (&quot;string manipulation&quot;).
As you can see, there's much more processing than if you'd have using just one simple query shown there.
<%@language=vbscript%>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>

<%
dim strConn,oConn,strSQL,oRS,arr_ext(),count,found,temp
strConn = &quot;driver={SQL Server};server=sergey;uid=sa;pwd=;database=pubs;&quot;
set oConn = server.CreateObject(&quot;ADODB.Connection&quot;)
oConn.Open(strConn)
strSQL = &quot;select fname,extension = right(fname,(len(fname)- charindex('.',fname,1))+ 1)from table_test where uid = 2&quot;
set oRS = oConn.Execute(strSQL)
oRS.MoveFirst
ReDim Preserve arr_ext(0)
arr_ext(0) = oRS(1)
Response.Write arr_ext(0)& &quot;<br>&quot;
oRS.MoveNext
do while not oRS.eof

found = False
temp = oRS(1)

For count = 0 To UBound(arr_ext)
If arr_ext(count) = temp Then
found = True
Exit For
Else
found = False
End If
Next
If found = False Then
ReDim Preserve arr_ext(UBound(arr_ext) + 1)
arr_ext(count) = temp
Response.Write arr_ext(count)& &quot;<br>&quot;
End If
oRS.MoveNext
Loop

%>

</BODY>
</HTML>
 
I have modified the code you gave me to suit my conditions and this is what I have got:

<html>
<head>
<title>BackPocket Web Interface</title>
</head>
<body>
</body>
</html>
<%
dim arr_ext(), found, count, temp
form_CustID =request.querystring(&quot;id&quot;)

strSQL = &quot;Select FileName from FileDescription where CustId = &quot; & form_CustID
Set rsFiles = Server.CreateObject (&quot;ADODB.Recordset&quot;)
rsFiles.Open strSQL ,&quot;DSN=Architron; UID=sa; PWD=&quot;


%>

<table align= &quot;center&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; BORDER=&quot;0&quot; WIDTH=&quot;800&quot; >
<tr><td align= &quot;center&quot; width=&quot;70&quot; bgcolor=#CCCCCC >File Types</td></tr>
<%

rsFiles.MoveFirst
ReDim Preserve arr_ext(0)
arr_ext(0) = rsFiles(1)
Response.Write arr_ext(0)& &quot;<br>&quot;
rsFiles.MoveNext


do While not rsFiles.EOF


found = False

file = rsFiles(&quot;FileName&quot;)
rtn = InStr(1,file, &quot;.&quot;)
if rtn > 0 then
extension = Right(file, (Len(file)-rtn+1))
end if

For count = 0 To UBound(arr_ext)
If arr_ext(count) = extension Then
found = True
Exit For
Else
found = False
End If
Next
If found = False Then
ReDim Preserve arr_ext(UBound(arr_ext) + 1)
arr_ext(count) = extension
Response.Write arr_ext(count)& &quot;<br>&quot;
End If

rsFiles.MoveNext
loop

for l=0 to 49
%>

<tr><TD BGCOLOR=&quot;#99FF99&quot;> <% Response.write extArray(l) %></TD></TR>
<%
next

%>
</table>
<%


rsFiles.Close
Set rsFiles = Nothing
%>

I have check it through and it looks ok to me, but I get an error saying :

ADODB.Fields error '800a0cc1'
ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.

/ftcustomer.asp, line 25


can you see whats wrong?

Thanks.

 
Taval,
sorry for the delay - I'm on vacation and opened forum just to find out what's going on.
The only place in your code which could give such an error is the line :
arr_ext(0) = rsFiles([red]1[/red]).
I hope this is the line 25
The problem is that you retrieving values for just one field from the table and the ordinal number,index,in Fields collection of the rsFiles for this field will be 0. That means that you should have written [red] rsFiles(0)[/red] instead of rsFiles(1) in your code. Or, in order not to get confused with all these indexes you better use fields' names in your code, like you did few lines below:
rsFiles(&quot;FileName&quot;),
this is the most safe way to do it.
 
guestg, I've tried changing it to what you recommened and I get no errors this time, the thing is every extension is displayed (with duplicates). I think the probelm is with the comparing of strings.

this works:

thisstring=&quot;taha&quot;
thatstring=&quot;taha&quot;

if strComp( thisstring, thatstring, 1 ) = 0 then
response.write &quot;the strings match&quot;
else
end if

but when I do this it gives me problems:

file = rsFiles(&quot;FileName&quot;)
rtn = InStr(1,file, &quot;.&quot;)
if rtn > 0 then
extension = Right(file, (Len(file)-rtn+1))
end if

<< I know that extension is &quot;.txt&quot;, by doing response.write on it&quot; >>

thisString= &quot;.txt&quot;

if strComp( thisString, extension, 1 ) = 0 then
response.write &quot;the strings match&quot;
else
end if

The above does not seem to work I think there is a problem comparing the strings, I have not declared extension as a string, but I haven't also declaerd thisstring and thatstring as stings either.

Grateful for any pointers, Thanks.

 
Taval,
there's just one thing left to solve this problem - you might need to trim rsFiles(&quot;FileName&quot;), because for some reason there could be spaces or other non-printable characters in files' names which don't let your code to work.
And maybe this is the best way to be safe while retrieving data from the database.
So, use this:
Trim(rsFiles(&quot;FileName&quot;))

But still you're not using the query that I posted to retrieve extensions right away.
Using this query you would save yourself a lot of troubles.
Anyway, good luck.
 
yeah your right, that was the problem, I was about to give up when I tried that and it worked. Thank you for all your help, I got that function to work now. :}

Taha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top