Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    2

    Unanswered: Array and Regular Expression problem

    I am pulling bus routes from a database by bus number and then pulling the stop times from each run. I then pull the first and last times from those arrays.

    This works fine, and will display the full routes:

    <%
    Routes = Array(Rs("Route1"), Rs("Route2"), Rs("Route3"))
    For Each Route in Routes
    %>
    <%=Route%><br />
    <%
    Next
    %>

    This also works fine, and will deliver the first and last time from one route:

    Route = Rs("Route2")
    Times = Trim(RegExpTest("(\s|(\s\d))\d:\d\d\s", Route))
    Function RegExpTest(patrn, strng)
    Dim regEx, Match, Matches, RetStr
    Set regEx = New RegExp
    regEx.Pattern = patrn
    regEx.IgnoreCase = True
    regEx.Global = True
    Set Matches = regEx.Execute(strng)
    For Each Match in Matches
    RetStr = RetStr & " " & Trim(Match.Value) & " "
    Next
    RegExpTest = RetStr
    End Function
    First = Trim(Left(Times,5))
    Last = Trim(Right(Times,5))
    %>
    <%=First%>
    <%=Last%>


    But combining the two fails. I haven't figured out why. Error message is
    a vbscript syntax error.


    Routes = Array(Rs("Route1"), Rs("Route2"), Rs("Route3"))
    For Each Route in Routes
    Times = Trim(RegExpTest("(\s|(\s\d))\d:\d\d\s", Route.Value))
    Function RegExpTest(patrn, strng)
    Dim regEx, Match, Matches, RetStr
    Set regEx = New RegExp
    regEx.Pattern = patrn
    regEx.IgnoreCase = True
    regEx.Global = True
    Set Matches = regEx.Execute(strng)
    For Each Match in Matches
    RetStr = RetStr & " " & Trim(Match.Value) & " "
    Next
    RegExpTest = RetStr
    End Function
    First = Trim(Left(Times,5))
    Last = Trim(Right(Times,5))
    %>
    <%=First%>
    <%=Last%>
    <% Next %>

    Any help would be deeply appreciated.

    Lee

  2. #2
    Join Date
    May 2004
    Posts
    2

    How dumb can I be?

    Why is the function inside the loop? Good question. As soon as I moved it outside the loop where it belongs, everything worked just fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •