[AccessD] Exchange Rate - Currency Converter thingy

Salakhetdinov Shamil mcp2004 at mail.ru
Fri Jun 29 17:08:06 CDT 2012


Hi Jack --

Yes, acquiring and stockpiling modern application software development "knowledge bits" while musing on code snippets here...

I have already noted ( in dba-VB) that LINQPad (http://linqpad.net)  could be used to prepare and to run C#, VB.NET, F# code snippets as well as to learn VB.NET and C# "easy way".
 LINQPad has a free as well as commercial versions.

Having got one of the VBA code snippets, which I have posted in this thread, I have put it into LINQPad, have done a few edits - and voila' - it works:

Public Sub Main()
Dim uri As String
uri = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"
Dim xmlDoc As Object 'New MSXML2.DOMDocument30
xmlDoc = Microsoft.VisualBasic.Interaction.CreateObject("MSXML2.DOMDocument.3.0")
xmlDoc.async = False
xmlDoc.Load (uri)
Dim xml As String
xml = xmlDoc.DocumentElement.xml
Dim pos1 As Integer
Dim pos2 As Integer
Dim currencyCode As String
currencyCode = "RUB"
pos1 = Microsoft.VisualBasic.Strings.InStr(xml, "currency=""" + currencyCode)
pos1 = Microsoft.VisualBasic.Strings.InStr(pos1, xml, "rate=""")
pos1 = Microsoft.VisualBasic.Strings.InStr(pos1 + 1, xml, """")
pos2 = Microsoft.VisualBasic.Strings.InStr(pos1 + 1, xml, """")
Dim currencyRate As String
currencyRate = Microsoft.VisualBasic.Strings.Mid(xml, pos1 + 1, pos2 - pos1 - 1)
dim output as string
output = "EUR/" + currencyCode + " => " + currencyRate
output.Dump("Test Result")
End Sub

Do you see many differences with VBA?

I then got that above VB.NET code snippet, copied it into clipboard, browsed to http://converter.telerik.com/, pasted it there, got it "automagically" converted into C# - and here it's working in LINQPad:

public void Main()
{
 string uri = null;
 uri = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml";
 dynamic xmlDoc = null;
 //New MSXML2.DOMDocument30
 xmlDoc = Microsoft.VisualBasic.Interaction.CreateObject("MSXML2.DOMDocument.3.0");
 xmlDoc.async = false;
 xmlDoc.Load(uri);
 string xml = null;
 xml = xmlDoc.DocumentElement.xml;
 int pos1 = 0;
 int pos2 = 0;
 string currencyCode = null;
 currencyCode = "RUB";
 pos1 = Microsoft.VisualBasic.Strings.InStr(xml, "currency=\"" + currencyCode);
 pos1 = Microsoft.VisualBasic.Strings.InStr(pos1, xml, "rate=\"");
 pos1 = Microsoft.VisualBasic.Strings.InStr(pos1 + 1, xml, "\"");
 pos2 = Microsoft.VisualBasic.Strings.InStr(pos1 + 1, xml, "\"");
 string currencyRate = null;
 currencyRate = Microsoft.VisualBasic.Strings.Mid(xml, pos1 + 1, pos2 - pos1 - 1);
string output = null;
 output = "EUR/" + currencyCode + " => " + currencyRate;
output.Dump("Test Result");
}

C# 4.0 with its new 'dynamic' data type has become the first class (MS Office) Automation code development tool - much more powerful than VBA is... 
Thank you.

-- Shamil 
Fri, 29 Jun 2012 16:57:30 -0400 от jack drawbridge <jackandpat.d at gmail.com>:
Thanks Shamil,

I agree with your comments re stockpiling. My stockpiling has been going on
a long time and is limited to a few tidbits and goodies gleaned from
AccessD and a few forums. I've been retired for 4 and a half years and may
just keep stockpiling and lurking - with a response every so often.

I hadn't seen anything with vba and interacting with webpage/webservice.
I'm using 2003 on XP and haven't quite gotten to Vb.net c#.net etc. It's
difficult to get into .Net when you're not working in the field every day.
Hard to remember from one concept to the next over a few days intermixed
with adding a porch to the cottage, electrical, plumbing, flooring and
finishing... and hopefully some fishing this year.


I enjoy the forum, even though participation is quite rare.

Jack
<<< skip >>>



More information about the AccessD mailing list