PDA

View Full Version : If ... Then statement isn't being recognized as complete


dravon
05-17-2006, 09:19 PM
Referring to the code borrowed from glenngv in the thread at http://www.codingforums.com/showthread.php?t=68639 which is quoted below, I'm having a problem with the second line shown in red.


For Each item In folder.Files
If regex.Test(item.path) Then
url = MapURL(item.path)
Response.Write("<li><a href=""" & url & """>" _
& item.Name & "</a> - " _
& item.Size & " bytes, " _
& "last modified on " & item.DateLastModified & "." _
& "</li>" & vbCrLf)
End If
Next


Using it as is, I get the following error: Expected ')' in regular expression. Based on this, my limited coding knowledge leads me to add a new ) as directed to get the new line of If regex.Test(item.path)) Then Results now say Expected 'Then'. Hrm... there is a "then" there... So I add another one as directed by the error code so now it looks like If regex.Test(item.path)) Then Then with the same results of Expected 'Then'. I tried removing all the parantheses on this line for the same results of Expected 'Then'. Pretty much from here on, whatever I tried (remove this, add that) I get the same Expected 'Then' results. At this point, now I'm going round in circles.

Is the .Test reference here supposed to be replaced with something specific to my code (like 'pathname' would be replaced)? It seems as if the code recognizes the If part of the statement but perhaps nothing is being properly set up so that it can't recognize the Then part of the statement. Any suggestions on how to look at this?

oracleguy
05-17-2006, 10:37 PM
Your code is correct, the error it seems is in your regex pattern. When the test is being preformed, its complaining because of a syntax error in the pattern and not the code you posted.

dravon
05-17-2006, 10:49 PM
That definitely helps!!! Thank you. Unfortunately, I don't know how to track down where the error is. :-( The code which creates/sets regex is

Set regex = New RegExp
if isarray(exclusionPattern) then
for each pattern in exclusionPattern
if strPattern < "" Then
strPattern = strPattern & "|\"& pattern
else
strPattern = "(\" & pattern
end if
next
if pat < "" then
strPattern = strPattern & ")$"
end if
regex.Pattern = strPattern
regex.IgnoreCase = True
end if

and the array referenced in isarray(exclusionPattern) comes for the following statements.

<% ListFolderContents Server.MapPath("/performance"), Array(".gif", ".jpg", ".xls", ".txt") %>
<% sub ListFolderContents(path, exclusionPattern)

While I've been able to decipher the RegExp calls, the rest is still Greek to me so I can't see any obvious errors here.