OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

A function for Calc to show the name of a month for number

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
ristoi
General User
General User


Joined: 25 Aug 2009
Posts: 26
Location: Järvenpää

PostPosted: Tue Nov 30, 2010 12:38 pm    Post subject: A function for Calc to show the name of a month for number Reply with quote

Here follows a Basic macro function NameMNr which can be used also as Calc function for listing month names. It works with one argument which take number 1 ... 12 for the month January ... December along with locale setting. So with Finnish locale setting it gives tammikuu ... helmikuu. With other small numbers there is no error message but 0 is January and - 1 is December so there is two Januarys if a series of numbers is used as arguments over zero value. There is no need for language packages for using different languages for month names but multiple foreign names of months can stay at spreadsheet only by Paste Special.

With no argument result is the name of the first month i.e. January with English locale.

Calc Halp page with header "User-Defined Functions" tells how to install this macro.

Code:

Function NameMNr (optional iKuuNro as Integer) as String
REM funktio palauttaa kuukauden nimen kuukausinumerosta
REM 1 = tammikuu (lokalisoituna)... 12 = joulukuu
REM 0 (tai jos argumentti puuttuu) = tammikuu, -1 = joulukuu
REM Ohjelmointi: RJ, avoin ja vapaa koodi

Dim lPvmnro as Long               'sisäinen päivämääränumero
Dim oFunktio as Object            'yleinen Funktio-objekti
Dim argumenttiluettelo As Variant   'Sisältää Calc-funktion argumentit
Dim iKKnro as Integer            'argumentti tarkistettuna

   If Ismissing(iKuuNro) or iKuuNro = 0  then
      iKKnro = 1
   else
      iKKnro = (iKuuNro) Mod 12
   EndIf
   If iKKnro = 0 then
      If iKuuNro > 0 then 
         iKKnro = 12
      else
         iKKnro = 1
      EndIf
   EndIf
      
   IF iKKnro < 0 then iKKnro = iKKnro + 13

   lPvmnro = Dateserial(2006,iKKnro,1)
   argumenttiluettelo=array(lPvmnro, "mmmm")

   oFunktio  = createUnoService("com.sun.star.sheet.FunctionAccess")
   NameMNr = oFunktio.callFunction("TEXT",argumenttiluettelo)
   
End Function 'NameMNr
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group