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

A macro function to show the name of a weekday for a number

Post new topic   Reply to topic Forum Index -> Code Snippets
View previous topic :: View next topic  
Author Message
General User
General User

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

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

Here follows a Basic macro function NameWDNr which can be used also as Calc function for producing weekday names corresponding weekday's number. It works with two arguments.

First argument takes number 1 ... 7 for day Sunday ... Saturday along with locale setting. So with Finnish locale setting it gives sunnuntai ... lauantai. With other small numbers there is no error message but 0 is Sunday and - 1 is Saturday so there is easily two Sundays if a serie of numbers is used as arguments over zero value.

Second argument is same as Calc's Weekday function's second argument for different type of starting and numbering weekdays.

There is no need for language packages for using different languages for weekday names but multiple foreign names of weekdays can stay at spreadsheet only by Paste Special.

With no arguments result is name of first day of week i.e. Sunday with English locale.

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


Function NameWDNr (optional iViikonPNro as Integer, optional iTyyppi as Integer) as String
REM funktio palauttaa viikonpäivän nimen viikonpäivän numerosta
REM Jos iViikonPNro puuttuu, palautetaan sunnuntai (lokalisoituna)
REM Jos iTyyppi on 1 tai puuttuu, niin iViikonPNro = 1 => sunnuntai (lokalisoituna)... 7 => lauantai
REM Kun iTyyppi on 2, niin iViikonPNro = 1 => maanantai ... 7 => sunnuntai
REM Kun iTyyppi on 3, niin iViikonPNro = 0 => maanantai ... 6 => sunnuntai
REM Vrt. Calcin Weekday-funktioon
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 iVPnro as Integer            '1. argumentti tarkistettuna
Dim iVTyyppi as Integer            '2. argumentti tarkistettuna
Dim bAlkaaMaanantaista as Boolean   'lippu, kun viikko alkaa maanantaista
   iVTyyppi = 1
   If NOT Ismissing(iTyyppi) then
      IF iTyyppi = 2 OR iTyyppi = 3 then
         bAlkaaMaanantaista = TRUE
         iVTyyppi = iTyyppi
   If Ismissing(iViikonPNro) then
      iVPnro = 1
      IF bAlkaaMaanantaista then
         If iTyyppi=3 then
            iViikonPNro = iViikonPNro + 2
            iViikonPNro = iViikonPNro + 1
      iVPnro = iViikonPNro Mod 7
   If iVPnro = 0 then
      If iViikonPNro > 0 then 
         iVPnro = 7
         iVPnro = 1
   IF iVPnro < 0 then iVPnro = iVPnro + 8

   lPvmnro = Dateserial(2006,1,iVPnro)
   argumenttiluettelo=array(lPvmnro, "nnn")

   oFunktio  = createUnoService("")
   NameWDNr = oFunktio.callFunction("TEXT",argumenttiluettelo)
End Function 'NameWDNr
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Forum Index -> 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