Click here to Skip to main content
Licence CPOL
First Posted 14 Jan 2009
Views 12,313
Downloads 133
Bookmarked 10 times

Number Speller COM-ponent

By | 18 Feb 2009 | Article
Component used to convert a numeric value into English/Romanian words in Excel

The original article: COM Number Speller.

Introduction

Some time ago, I needed to print numbers as text in Excel (Office 2003 as far as I remember). Searching the internet, I found a solution for English language, but not for Romanian language.

So, I created a reusable piece of code that may be easily used in as many environments as possible. I chose COM and ATL to be the solution to this problem. This is also a good programming exercise for my rusty COM / C++ skills and I plan to use it as a template for all my future COM objects.

Using the Code  

To install the COM object, just simply run Install.bat in NumberSpeller.zip archive.
Here is the Excel macro that makes use of the NumberSpeller COM object:

Function Spell(n As Currency) As String
'Create the speller object.
Dim s As NumberSpellerLib.speller
Set s = New NumberSpellerLib.speller

Dim o As Object
Set o = s
o.Language = "ro"
Spell = o.Translate(n)
End Function

Here is another example of using the component from WSH script:

// Create the speller object.
var speller = new ActiveXObject("NumberSpeller.Speller");

// Set Romanian language
speller.language = "en";

////////////////////////////////////////////
// Modify the  number constant below.
var numberToTranslate = 101001;

// Translate number to text.
try
{
    var textNumber = speller.Translate(numberToTranslate);
    WScript.Echo(textNumber);
}
catch (e)
{
    // Display details about any thrown exceptions.
    WScript.Echo(e.name + ": " + e.description + "  " + e.number);
}

Points of Interest

  • Error info support by implementing IErrorInfo interface.
  • Help in CHM format and context identifiers specified in MIDL source file.
  • BSTR manipulation using CComBSTR class provided by ATL
  • IDispatch support, so the component can be used from scripting environments.
  • Spelling implementation itself and support for multiple languages (only Romanian and English for now).  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Adrian Dorache

Software Developer (Senior)
Codecentrix Software
Romania Romania

Member

Software consultant in Bucharest Romania writing Windows programs and browsers plug-ins since 1998 with Visual C++.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood job! PinmemberMaze6:52 27 May '09  
GeneralModified English Version PinmemberSynaptrik7:54 18 Feb '09  
JokeRe: Modified English Version PinmemberAdrian Dorache9:21 18 Feb '09  
GeneralRe: Modified English Version PinmemberSynaptrik9:23 18 Feb '09  
Generalseventeen is mispelled.. PinmemberSynaptrik13:59 17 Feb '09  
GeneralRe: seventeen is mispelled.. PinmemberAdrian Dorache3:13 18 Feb '09  
QuestionCom Component? Why? Pinmemberednrg5:32 14 Jan '09  
AnswerRe: Com Component? Why? PinmemberAdrian Dorache5:55 14 Jan '09  
Because I wanted it to be available from script languages like Jscript and other non .Net environments. However it can be used from .Net languages as well.
 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 18 Feb 2009
Article Copyright 2009 by Adrian Dorache
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid