LotusScript Class to Convert Numbers to Words in French

A bit of an obscure one this, but we are making an English application multi lingual. One function converts numbers to words, and having tried to use the same logic for the French translations it just doesn’t work so I spent a couple of hours this morning porting a Java class to work in LotusScript to perform the function:

'**********************************************************
'*Ported from Java Class found at:
'*http://www.rgagnon.com/javadetails/java-0426.html
'**********************************************************
Class FrenchDecimalFormat
  tenNames() As String
  uniteNames1() As String
  uniteNames2() As String
  
  Sub new()
    Redim tenNames(9)
    tenNames(0) = ""
    tenNames(1) = ""
    tenNames(2) = "vingt"
    tenNames(3) = "trente"
    tenNames(4) = "quarante"
    tenNames(5) = "cinquante"
    tenNames(6) = "soixante"
    tenNames(7) = "soixante"
    tenNames(8) = "quatre-vingt"
    tenNames(9) = "quatre-vingt"
    
    Redim uniteNames1(19)
    uniteNames1(0) = ""
    uniteNames1(1) = "un"
    uniteNames1(2) = "deux"
    uniteNames1(3) = "trois"
    uniteNames1(4) = "quatre"
    uniteNames1(5) = "cinq"
    uniteNames1(6) = "six"
    uniteNames1(7) = "sept"
    uniteNames1(8) = "huit"
    uniteNames1(9) = "neuf"
    uniteNames1(10) = "dix"
    uniteNames1(11) = "onze"
    uniteNames1(12) = "douze"
    uniteNames1(13) = "treize"
    uniteNames1(14) = "quatorze"
    uniteNames1(15) = "quinze"
    uniteNames1(16) = "seize"
    uniteNames1(17) = "dix-sept"
    uniteNames1(18) = "dix-huit"
    uniteNames1(19) = "dix-neuf"
    
    Redim uniteNames2(10)
    uniteNames2(0) = ""
    uniteNames2(1) = ""
    uniteNames2(2) = "deux"
    uniteNames2(3) = "trois"
    uniteNames2(4) = "quatre"
    uniteNames2(5) = "cinq"
    uniteNames2(6) = "six"
    uniteNames2(7) = "sept"
    uniteNames2(8) = "huit"
    uniteNames2(9) = "neuf"
    uniteNames2(10) = "dix"
  End Sub
  
  Function convertZeroToHundred(number As Integer) As String
    Dim laten As Integer
    Dim lUnite As Integer
    Dim result As String
    Dim joiner As String
    laten = Fix(number / 10)
    lUnite = number Mod 10
    result = ""
    
    If laten = 1 Or laten = 7 Or laten = 9 Then
      lUnite = lUnite + 10
    End If
    
    joiner = ""
    If laten > 1 Then
      joiner = "-"
    End If
    If lUnite = 0 Then
      joiner = ""
    Elseif lUnite = 1 Then
      If laten = 8 Then
        joiner = "-"
      Else
        joiner = " et "
      End If
    Elseif lUnite = 11 Then
      If laten = 7 Then
        joiner = " et "
      End If
    End If
    If laten = 0 Then
      result = uniteNames1(lUnite)
    Elseif laten = 8 Then
      If lUnite = 0 Then
        result = tenNames(laten)
      Else
        result = tenNames(laten) + joiner + uniteNames1(lUnite)
      End If
    Else
      result = tenNames(laten) + joiner + uniteNames1(lUnite)
    End If
    
    
    convertZeroToHundred = result
  End Function
  
  Function convertLessThanOneThousand(number As Integer)
    Dim hundreds As Integer
    Dim remainder As Integer
    Dim strRemainder As String
    Dim result As String
    hundreds = Fix(number / 100)
    remainder = number Mod 100
    strRemainder = convertZeroToHundred(remainder)
    
    If hundreds = 0 Then
      result = strRemainder
    Elseif hundreds = 1 Then
      If remainder > 0 Then
        result = "cent " + strRemainder
      Else
        result = "cent"
      End If
    Else
      If remainder > 0 Then
        result = uniteNames2(hundreds) + " cent " + strRemainder
      Else
        result = uniteNames2(hundreds) + " cents"
      End If
    End If
    convertLessThanOneThousand = result
  End Function
  
  Function convert(number As Double)
    Dim snumber As String
    Dim billions As Integer
    Dim millions As Integer
    Dim hundredthousands As Integer
    Dim thousands As Integer
    Dim strBillions As String
    Dim strMillions As String
    Dim strHundredThousands As String
    Dim strThousands As String
    Dim result As String
    If number = 0 Then
      convert = "zéro"
      Exit Function
    End If
    
    snumber = Cstr(number)
    snumber = Format$(number, "000000000000")
    billions = Cint(Left$(snumber, 3)) ' XXXnnnnnnnnn
    millions  = Cint(Mid$(snumber, 4,3)) ' nnnXXXnnnnnn
    hundredthousands = Cint(Mid$(snumber, 7, 3))  ' nnnnnnXXXnnn
    thousands = Cint(Mid$(snumber, 10, 3))  ' nnnnnnnnnXXX
    
    If billions = 0 Then
      strBillions = ""
    Elseif billions = 1 Then
      strBillions = convertLessThanOneThousand(billions) + " milliard "
    Else
      strBillions = convertLessThanOneThousand(billions) + " milliards "
    End If
    result =  strBillions
    
    If millions = 0 Then
      strMillions = ""
    Elseif millions = 1 Then
      strMillions = convertLessThanOneThousand(millions) + " million "
    Else
      strMillions = convertLessThanOneThousand(millions) + " millions "
    End If
    result = result + strMillions
    
    If hundredthousands = 0 Then
      strHundredThousands = ""
    Elseif hundredthousands = 1 Then
      strHundredThousands = "mille "
    Else
      strHundredThousands = convertLessThanOneThousand(hundredthousands) + " mille "
    End If
    result = result + strHundredThousands
    
    strThousands = convertLessThanOneThousand(thousands)
    result =  result + strThousands
    
    convert = result
  End Function
End Class���

Tags: Show-N-Tell Thursday

Ball Juggling

Life isn’t wonderful at the moment, progress on the house move seems to be slowing down (if that’s possible), an ex-colleague who I worked with for several years passed away while doing charity work in South America during the week, and, most importantly at the moment my Dad had a bit of an accident midweek. He fell off the roof of his house and hurt his back quite badly which required an operation on Thursday. It seems to have gone OK but as with any serious injury like this it will be a long, slow recovery.

To be honest the end of this month can’t come fast enough at the moment!

The big migration

Well I’ve spent a few hours today moving this site, 50WordReview and Defectr across to the new, properly hosted server. I’ve been very lucky to be offered to share a FastHosts dedicated server that has plenty of disk space, memory and, most importantly, a big, unlimited internet connection. Big thanks go to Mark Myers, hopefully you’ll all notice the difference when using Defectr.

Now, I just need to get back to the real work and deal with all of the feature requests I’ve received for Defectr! Oh well who needs weekends anyway.

Charting in your browser

The system that I am working on (for one of my clients) required some online reporting functionality. They have a "proper" corporate reporting system in place and we do plan to send all of the Domino data into that at some point but it’s a big job to create the SQL database etc. So in the meantime I’ve been playing for a couple of days with WebFX Chart. This is a truly great set of code that you can drop into a website and be generating pretty impressive looking charts from very quickly. I would put up some screenshots but the data is confidential, you get a very good idea from the demo site though.

I have created a dynamic report generator that uses AJAX and Java with 7 or 8 different templates which covers most of the reporting requirements for the short term, and all it took was six hours development effort and a bit of reading, gotta love the internet sometimes :o)

What a week

This week has just been crazy so far. After the Ed-dotting on Monday Defectr has been chugging along relatively happily. My call for hosting advice got offers of hosting from several people, just more evidence of how supportive the Domino community is after all of the silliness in the last couple of weeks with the whole Rod Boothby thing. In the end I have decided to share a dedicated server hosted by Fasthosts with a friend, should make a big difference to the performance of all of my sites, but Defectr in particular will benefit.

Other than all that stuff, my house move is gradually moving forwards, the people buying my place are pushing for completion but the flat I am buying is going a little more slowly so my solicitor is doing a great job of trying to keep the two transactions in sync. At the moment, due to the delays in my purchase it’s not looking good for a November completion but hopefully I can help to speed things along. I really would prefer to be moved before getting into the Christmas party season!

I guess everyone is aware by now, but IE7 has gone gold and will be pushed out by Microsoft using Windows Update, so you need to make sure that your applications are tested before your users start complaining. Check out Jake’s article for a good rundown of what you should be doing

This day in history

Make history with us on 17 October by taking part in the biggest blog in history.

‘One Day in History’ is a one off opportunity for you to join in a mass blog for the national record. We want as many people as possible to record a ‘blog’ diary which will be stored by the British Library as a historical record of our national life.

Link via Fiona White

Oops, I’ve been Ed-Dotted

OK guys, apologies for the appalling performance of Defectr. The feedback from you all was incredible before Ed posted a link this afternoon, since when the server has been churning away like a good’un. I am going to try and sort out a proper hosting solution ASAP but until then please bear with me.

By the way, can anyone suggest a good hosting company, I’m tempted to just rent a dedicated server but that seems a pricey option?

New Application

Well, the application I’ve been playing with in my spare time recently has reached a point where I’m not too embarrassed to let it be seen in public.

What is it?
Well it’s a simple defect tracking application, allowing you to log, monitor and work on development or production issues for small projects.

Why should I be interested?
If you’re a Domino developer, then it may be worth a look as pretty much the whole site has been developed using the Dojo framework. This ranges from the block layout (positioning isn’t done with CSS but with the LayoutContainer widget) to use of the rich text editor widget and right through to control of form submission using the io application support library and lots of other stuff in between.

If you’re involved in small projects (by which I mean involving teams of less than ten people) and don’t currently have a system in place to track the development, testing and support of your application then this is good a place as any to start.

It’s free!

Uh Oh!
If you’ve found a bug then… shush, don’t let everyone know! No actually please do so that I can have a look into the problem. Either leave a comment here or fill in the Contact Us page on the site. I’ve done testing in Firefox and IE on Windows and basic checks in Firefox and Safari on the Mac but there’s such a huge number of browsers and configurations out there that I’ve almost certainly missed things.

And if you’ve got any questions or ideas then please drop me a line.

ND 7.0.2 and RSS

I’ve had 7.0.2 installed for 10 days now and have spent a little time playing with the new features. First thing to say is that generally it’s a great release, stable, some much requested features have been added, all well communicated. This is the way all software releases should be run.

I think my expectations of the RSS generator may have been a little too much though. The basic generator is great, it makes publishing flat feeds very easy, so if you’re just getting into RSS then it’s well worth a look. But I have a few issues once you begin to do anything a little more complex…

My first worry is that the generation is handled by an agent, not a problem for low volume sites but once you’ve published a few feeds and have several hundred subscribers you’ll be looking at thousands of page loads per day, I would have much preferred the XML be served out by a view instead. I know that’s a big ask, it’s effectively a new design element then, but hey you’ve got to ask for these things to keep the Lotus guys on their toes.

Now onto my specific problems. I, like most people, prefer to run my web sites using session authentication, which means that if you want to serve personalised RSS feeds out to users you need to create a separate site configuration which is set up to handle simple authentication. Not a big problem, but I was led to understand that 7.0.2 was going to offer the ability to selectively serve some URL’s out via simple authentication from within one site. I can’t for the life of me find out where that’s configured, or if I just misunderstood what was being given to us.
Update: Chris Linfoot has found the problem, he describes the solution in the comments here

Onwards then. The reason I wanted to allow authenticed RSS feeds was to allow people to subscribe to a view of "My Items" within a database. They can see all documents in the database but need to be notified when a document is assigned to them. According to the RSS configuration database, you shouldn’t use categorized views, so how do I build the list of documents which each individual user needs to be told about.

All of the above are specific to my own implementation and have pretty obvious work arounds within the application, I was just hoping that some of the heavy lifting was going to be taken off my hands by the server. Oh well, for me it’s continued use of hand rolled RSS for a while longer.