Microsoft KB Archive/914200

= How to convert European currencies programmatically by using the Excel MSoEuro component and how to use the Euro Currency Tools add-in =

Article ID: 914200

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Office Excel 2003
 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 2000 Standard Edition
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio 2005 Express Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Team System Architect Edition
 * Microsoft Visual Studio 2005 Team System Developer Edition
 * Microsoft Visual Studio 2005 Team System Test Edition

-





SUMMARY
This article describes how to use the Convert method of the Microsoft Excel MSoEuro component in Microsoft Visual Studio .NET. You can use this method to convert currencies programmatically to euros or to another euro nation's currency. Also, you can use this method to convert currencies programmatically from euros or from another euro nation's currency. This article also describes how to use the Euro Currency Tools add-in in Microsoft Excel 2000 or a later version of Excel.



Requirements
The following list includes the software that is required to complete this task:
 * Visual Studio .NET 2002 or a later version of Visual Studio
 * Excel 2000 or a later version of Excel
 * Euro Currency Tools add-in

How to install the Euro Currency Tools add-in
To install the Euro Currency Tools add-in, follow these steps:
 * 1) Start Excel.
 * 2) On the Tools menu, click Add-ins.
 * 3) Click to select the Euro Currency Tools check box, and then click OK.

About the MSoEuro component
The MSoEuro component provides the Convert method. The Convert method can convert currencies in the following three ways:
 * From a euro nation's currency to euros
 * From euros to a euro nation's currency
 * From one euro nation's currency to another euro nation's currency by using euros as an intermediary

The Convert method returns the converted number as a double variable. The Convert method takes the following five arguments. Convert (Value, CurrencyFrom, CurrencyTo, FullPrecision, TriangulationPrecision) The five arguments are defined in the following list:
 * The Value argument is a double variable. This argument is the number of units of currency that you want to convert.
 * The CurrencyFrom argument is a string variable. This argument is the three letter code that indicates the unit of currency that you are converting from.
 * The CurrencyTo argument is a string variable. This argument is the three letter code that indicates the unit of currency that you are converting to.
 * The FullPrecision argument is a Boolean variable. This argument specifies how to display the returned number. If this argument is set to true, all significant digits from the conversion are displayed. If this argument is set to false, not all significant digits from the conversion are displayed. By default, this argument is set to false.
 * The TriangulationPrecision argument is an integer variable and is greater than or equal to 3. When the Convert method of the MSoEuro component converts one euro nation's currency to another euro nation's currency, the Convert method can round the intermediate euro value. This argument specifies how many digits to use when the Convert method rounds the intermediate euro value. If you omit this argument, the Convert method does not round the intermediate euro value.

Codes for European currencies
The following currency codes are available in the Convert method.

How to use the MSoEuro component to convert euros programmatically
To use the MSoEuro component to convert euros programmatically, follow these steps:  Start Visual Studio. Create a new console application by using Microsoft Visual Basic or by using Microsoft Visual C#. Add a reference to the Microsoft Office Euro Converter Object Library (Msoeuro.dll).  Insert the following code into the console application. For a Microsoft Visual C# console application, insert the following code in the static void Main method. MsoEuro.Converter objEuro=null;

try {      //Use MSOEURO.dll for currency conversion objEuro=(MsoEuro.Converter) Activator.CreateInstance(Type.GetTypeFromProgID( &quot;MsoEuro.Converter&quot;));

//Show DLL version Console.WriteLine(&quot;msoeuro.dll version : &quot; + objEuro.Version); } catch {   //DLL not found Console.WriteLine(&quot;Please check the Installation of MSOEURO.dll on your PC.&quot;); Console.Read;

System.Environment.Exit(0); }

//Value for currency conversion const string CurrencyFrom = &quot;EUR&quot;; const string CurrencyTo = &quot;ITL&quot;; double SourceValue = 1; // 1 Euro const bool FullPrecision = true; const int TriangulationPrecision = 5; double ResultValue;

//Call DLL for currency conversion ResultValue =objEuro.get_Convert(SourceValue,CurrencyFrom,CurrencyTo,FullPrecision,TriangulationPrecision); Console.WriteLine(&quot;Result is : &quot; + ResultValue); Console.ReadLine; For a Visual Basic .NET console application, insert the following code in the Sub Main method. Dim objEuro As MsoEuro.Converter

Try

'Use MSOEURO.dll for Currency conversion objEuro = CreateObject(&quot;MSOEURO.Converter&quot;) 'Show DLL version Console.WriteLine(“msoeuro.dll version : “ & objEuro.Version)

Catch ex As Exception

'DLL not found Console.WriteLine(&quot;Please check the Installation of MSOEURO.dll on your PC.&quot;) Console.Read

End End Try

'Default value for Currency conversion Const CurrencyFrom As String = &quot;EUR&quot; Const CurrencyTo As String = &quot;ITL&quot; Dim SourceValue As Decimal = 1 ' 1 Euro Const FullPrecision As Boolean = True Const NumDigitsAfterDecimal As Integer = 2 Dim ResultValue As Decimal

'Call DLL for Currency conversion ResultValue =FormatNumber(objEuro.Convert(SourceValue,CurrencyFrom,CurrencyTo, _ FullPrecision), NumDigitsAfterDecimal)

Console.WriteLine(“Result is : “ & ResultValue) Console.Read   Save and then run the console application.

Note You receive the following output. msoeuro.dll version : 1.0.128 Result is : 1936,27 

