VBScript RegExp only working with access2007 ?

A

Alexcamp

Hello all,

Using the modified code below that was obtained from the thread at
http://www.accessmonster.com/Uwe/Fo...ess/39625/Live-exchange-rate-data-into-Access , I got it to work fine, but only in access 2007. When I open my
form in Access2003, the function will return 0 instead of the desired rate.

Does anyone know why?
Thanks


Public Function exchangeRate2#()
Dim xmlHttpRequest As Object
Dim rawHTML$
Dim regularExpression As Object
Dim matches As Object
Dim match As Object

On Error Resume Next
'will return zero on error

' class and server names may have to be modified
' download available at
' http://www.microsoft.com/downloads/...CF-3BCF-4009-BE21-27E85E1857B1&displaylang=en

Set xmlHttpRequest = CreateObject("MSXML2.XMLHTTP.6.0")
With xmlHttpRequest
.Open "GET", "http://www.bloomberg.com/markets/currencies/fxc.html", False
.send
rawHTML = .responseText
End With

Set regularExpression = CreateObject("VBScript.RegExp")
With regularExpression
.pattern = "CAD<\/span><\/td><td bgcolor=" & Chr$(34) & "white" & Chr$(34)
& " align=" & Chr$(34) & "right" & Chr$(34) _
& "><span class=" & Chr$(34) & "style5" & Chr$(34) & ">(\d\.\d{0,4})<\
/span><\/td><td bgcolor=" & Chr$(34) & "white" & Chr$(34) & " align=" & Chr$
(34) & "right" & Chr$(34) _
& "><span class=" & Chr$(34) & "style5" & Chr$(34) & ">(\d\.\d{0,4})<\
/span><\/td>"
.pattern = Replace(.pattern, Chr$(34), "\" & Chr$(34))
.ignoreCase = True
Set matches = .Execute(rawHTML)
Set match = matches(0)
exchangeRate2 = match.SubMatches(0) + 0.006

End With
 
I

ihawaiian

The code is working the way it's supposed to. On Error Resume Next means in
case of error, set it to 0 and run the next line of code. It's used to
ignore errors, and your code is ignoring the error.

Good programmers use error handlers to tell them what errors occur and then
they modify the code for those errors. Add an error handler to the
procedure, and it will tell you what the problem is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top