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

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.

More Information

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 Toolscheck 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.
Country/regionBasic unit of currencyISO code
BelgiumFrancBEF
LuxembourgFrancLUF
Germany Deutsche MarkDEM
SpainPesetaESP
FranceFrancFRF
IrelandPoundIEP
ItalyLiraITL
NetherlandsGuilderNLG
AustriaSchillingATS
PortugalEscudoPTE
FinlandMarkkaFIM
GreeceDrachmaGRD
Euro nationsEuroEUR

How to use the MSoEuro component to convert euros programmatically

To use the MSoEuro component to convert euros programmatically, follow these steps:
  1. Start Visual Studio.
  2. Create a new console application by using Microsoft Visual Basic or by using Microsoft Visual C#.
  3. Add a reference to the Microsoft Office Euro Converter Object Library (Msoeuro.dll).
  4. 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( "MsoEuro.Converter"));

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

    System.Environment.Exit(0);
    }

    //Value for currency conversion
    const string CurrencyFrom = "EUR";
    const string CurrencyTo = "ITL";
    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("Result is : " + 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("MSOEURO.Converter")
    'Show DLL version
    Console.WriteLine(“msoeuro.dll version : “ & objEuro.Version)

    Catch ex As Exception

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

    End
    End Try

    'Default value for Currency conversion
    Const CurrencyFrom As String = "EUR"
    Const CurrencyTo As String = "ITL"
    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()
  5. Save and then run the console application.

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

References

For more information about the Microsoft Office Euro Currency Tools, visit the following Microsoft Web site: For more information about how to add and remove references in Visual Basic or in Visual C#, visit the following Web site:

For more information about the Excel 2000 SR-1 Eurotool Add-In Update, click the following article number to view the article in the Microsoft Knowledge Base:

295681 How to obtain and install the Excel 2000 SR-1 Eurotool Add-In update

Propriedades

ID do Artigo: 914200 - Última Revisão: 23 de mar de 2009 - Revisão: 1

Comentários