Salakhetdinov Shamil
mcp2004 at mail.ru
Sat Jun 30 13:02:49 CDT 2012
Thank you, Stuart, Let's call it "XMLHTTPSample" sample. Here is a VB.NET equivalent: I have had to pass also Async flag parameter set to False, otherwise it would try to parse response xml before actual response has arrived. Module XMLHTTPSample Public Function GetExchRate(strCurr As String) As String 'VBA code to retrieve exchange rate against Euro 'strCurr should be the three letter currency code Dim oHTTP As Object Dim lngresult As Long Dim strPage As String strCurr = UCase$(strCurr) oHTTP = CreateObject("Msxml2.XMLHTTP") lngresult = oHTTP.Open("GET", "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml", False) lngresult = oHTTP.Send("") strPage = oHTTP.Responsetext oHTTP = Nothing lngresult = InStr(strPage, "currency='" & strCurr & "'") GetExchRate = "EUR/" & strCurr & " => " & Val(Mid$(strPage, lngresult + 21)) End Function End Module And here is yet another VB.NET version using WebClient and RegEx (just to keep the game going :)) - tested in LINQPad - with System.Net as Additional Namespace Imports: Dim currencyCode As String = "RUB" ' normal syntax Dim xml As String = (New WebClient).DownloadString("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml") Dim input As String = "currency='{0}'\srate='(?'rate'[0-9]*\.[0-9]*)'" Dim r As Regex = New Regex(String.Format(input, currencyCode)) r.Match(xml).Groups("rate").Value.Dump ' fluent syntax Dim rate As Decimal = _ Decimal.Parse(( _ New Regex("currency='{0}'\srate='(?'rate'[0-9]*\.[0-9]*)'" _ .Replace("{0}", currencyCode)) _ .Match(((New WebClient).DownloadString( _ "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"))) _ .Groups("rate").Value.ToString)) rate.Dump Thank you. -- Shamil Sat, 30 Jun 2012 21:40:31 +1000 от "Stuart McLachlan" <stuart at lexacorp.com.pg>: I decided to play as well :-) Function GetExchRate(strCurr As String) As String 'VBA code to retrieve exchange rate against Euro 'strCurr should be the three letter currency code Dim oHTTP As Object Dim lngresult As Long Dim strPage As String strCurr = UCase$(strCurr) Set oHTTP = CreateObject("Msxml2.XMLHTTP") lngresult = oHTTP.Open("GET", "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml") lngresult = oHTTP.Send("") strPage = oHTTP.Responsetext Set oHTTP = Nothing lngresult = InStr(strPage, "currency='" & strCurr & "'") GetExchRate = "EUR/" & strCurr & " => " & Val(Mid$(strPage, lngresult + 21)) End Function On 29 Jun 2012 at 22:58, Mark Simms wrote: > > Do you see many differences with VBA? > > Extreme verbosity....not elegant at all. > > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com