9 Replies Latest reply on Nov 19, 2007 12:55 AM by Alibented

    getting the date

    Alibented
      I am trying to get the day of the week. My book tells me this is not possible with Directors lingo,but by using Flash lingo it is.
      I am instructed to write "put integer(objFlashDate.getDate())" in the Message window and should expect to see a value between 0 and 6, indicating the day of the week.
      The answer I am getting is: "Script error: Object expected".
      I'm unable to find what I am doing wrong. Any suggestions ?
      Thanks, Ted
        • 1. Re: getting the date
          Level 7
          The built-in UIHelper xtra has a getDate() function that will tell you
          the date (not the day of the week).

          put getDate()
          -- [107,11,17]

          There is another built-in function called the long date which will give
          you the day of the week as well as the date, though the format that it
          takes will be different on different machines. It uses the OS's date
          settings. On my machine, it looks like this:

          put the long date
          -- "Saturday, November 17, 2007"

          on another machine, it may have the words in a different order, if they
          set up their computer to display it differently.

          The BuddyAPI xtra (which is free to use up to 2 functions of) has the
          best solution. There is a baSystemTime() function which will tell you
          any of the time, day, or date information in any format you choose.
          Check the docs that come with it for syntax. You can download it from
          www.mods.com.au/budapi

          put baSystemTime("%A")
          -- "Saturday"
          • 2. Re: getting the date
            here's a plain lingo handler to get the weekday:

            -----------------------
            on mGetWeekDay dateObject, lang
            if ilk(dateObject) <> #date then dateObject = the systemdate
            vN = (dateObject - date(20030505)) mod 7
            vN = vN + 1 + (7 * (vN < 0))
            case lang of
            "de":
            li = ["Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"]
            "pt":
            li = ["Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado","Domi ngo"]
            "fr":
            li = ["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"]
            "es":
            li = ["Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo"]
            "it":
            li = ["Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato","Domenica"]
            "en":
            li = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
            otherwise:
            return vN
            end case
            return li.getAt(vN)
            end
            --------------------------

            this handler takes two parameters, which are both optional:
            if <dateObject> is not a date object, todays date is taken.
            if <lang> is not one of the strings in the case statement an integer is returned (1=Monday and 7=Sunday) otherwise you get the translated weekday.

            • 3. Re: getting the date
              Alibented Level 1
              When asking for the day of the week I need an answer in the for of an integer or string.
              So "put getDate()" nor "put the long date" are useful to me.
              "put baSystemTime(%)" seemed to be useful for me, but is giving me a Script error: Handler not defined

              I am not experienced enough to know what to do with the "on mGetWeekDay dateObject, lang" solution

              An answer in the form of an integer seems to be the best, as it will be uneffected be the computer language settings
              • 4. Re: getting the date
                Level 1
                quote:

                I am not experienced enough to know what to do with the "on mGetWeekDay dateObject, lang" solution


                Create a new movie script member (or use an existing script member) and paste the above text from "on " until the last "end" into that script.
                This is called a lingo handler and then you can call from any other script "mGetWeekDay()" to get the weekday as integer.

                start with opening the message window and type:

                put mGetWeekDay()

                and hit the return key. it should give you a result like:
                -- 7

                now do something like:

                weekday = mGetWeekDay()
                put weekday
                -- 7

                you just assigned the result of the function "mGetWeekDay", which is defined in your script between the "on ... end" part, to the variable "weekday", which you can furrther use.

                But honestly, you should read up a bit more about these basic things, because you won't get far with the finction nor the result of the function, if you don't know, what a function definition (lingo: handler) is and what to do to use it.



                • 5. Re: getting the date
                  Alibented Level 1
                  Alex,
                  I have tried that, but it does not work.
                  I have created a movie script and copied and pasted your text into it
                  Next I opened the Message window and typed:
                  put mGetWeekday()
                  But I am getting a warning:
                  Script error: Handler not defined
                  put mGetWeekDay()
                  #mGetWeekDay

                  On typing:
                  weekday = mGetWeekday()
                  put weekday
                  I get: -- <Void>

                  I am using Director MX, could that be a reason?
                  Thanks for your help, Ted
                  • 6. Re: getting the date
                    Level 1
                    quote:

                    I am using Director MX, could that be a reason?


                    no.
                    the handler should work in director 8 upwards.

                    either the script you created is not of type #movie or it is not yet compiled. that is: you pasted the handler and executed the message window line without either closing the script editor (which compiles the script) or choosing the little "compile script" button (that's the one, whicch looks like a lightning) or choosing "recompile all scripts" from the "Control" menu.

                    other than that your script is not of type #movie. select the member, opene the Property Inspector (press the blue "i" button for example) and make sure, that in the "Script" tab the "Type" pop up menu reads "Movie".

                    • 7. Re: getting the date
                      Alibented Level 1
                      Alex,
                      I had not closed (compiled) the movie script.
                      It is working now, thanks !
                      Could you explain the 6 different languages li = ["Montag", ......... etc you used to me?
                      Before I realised that I needed to close or compile the movie script, I tried adding the Dutch names of the week to the movie script, since my computer is set in the Dutch language.
                      This had no result, but now I removed all the languages except the Portugese, and it is still working.
                      This puzzles me.
                      • 8. Re: getting the date
                        Level 1
                        quote:

                        Before I realised that I needed to close or compile the movie script, I tried adding the Dutch names of the week to the movie script, since my computer is set in the Dutch language.
                        This had no result, but now I removed all the languages except the Portugese, and it is still working.
                        This puzzles me.


                        it is a case statement, which depends on the second parameter you pass to the function.
                        the second parameter is supposed to be a string. currently the following strings work:

                        "de" = german
                        "pt" = portuguese
                        "fr" = french
                        "es" = spanish
                        "it" = italian
                        "en" = english

                        if the paramter is ANYTHING other (including void -> no value at all) then you get the integer for the weekday as return value.

                        If you want to add dutch just add annother case to the case statement. for example:

                        "nl":
                        li = ["your", "seven", "dutch", "weekdays", "here", "just make sure", "that here are at least seven items in this list"]

                        now you can get something like:
                        put mGetWeekDay(void, "nl")
                        -- "your"



                        Don't forget to post this list with the dutch weekday names back here so I can add them to my handler.

                        • 9. Re: getting the date
                          Alibented Level 1
                          OK.
                          Here is the string containing the Dutch weekday names:
                          "nl":
                          li = ["Maandag","Dinsdag","Woensdag","Donderdag","Vrijdag","Zaterdag","Zondag"]
                          Thanks for your help