In this function below I am trying to fetch exchnage rates from a central bank website, which will give you an XML page for each date you request, and since weekends and public holidays are without exchange rates I have to go one day prior to that and try again until I get an exchange rate. The initially entered date is also to be taken a day back, so I do that in the beginning with “tarih=tarih-1”.
This function works the way I want but occasionally gives me this error:
Type: com.sun.star.lang.IllegalArgumentException
…for this line:
xml_string = svc.callFunction("WEBSERVICE", array(mbpage))
for instance if the date entered is 01.02.2021 (i.e. first of February).
Any help appreciated.
function kur(tarih as date, parabirimi as string) as currency
on error goto hata
dim svc as object
dim mbpage as string
dim counter as integer
kur()=0.0
counter=1
tarih=tarih-1
svc = createUnoService( "com.sun.star.sheet.FunctionAccess" )
top:
mbpage = "http://www.tcmb.gov.tr/kurlar/" & year(tarih) & format(month(tarih),"0#") & "/" & format(day(tarih),"0#") & format(month(tarih),"0#") & year(tarih) & ".xml"
xml_string = svc.callFunction("WEBSERVICE", array(mbpage))
kur() = svc.callFunction("FILTERXML", array(xml_string, "number(/Tarih_Date/Currency[@CurrencyCode='"+ucase(parabirimi)+"']/ForexBuying)"))
exit function
hata:
if (counter > 5) then
kur()=0.0
exit function
end if
counter=counter+1
tarih=tarih-1
goto top
end function