/ Forums / Advansys Formativ / Creating Solutions with Formativ / Appointment duration from DateTime controls

  • Creator
    Topic
  • #4354
    dgerisch
    Participant

      I have an applet I’m working on that creates a dialog box to present to the user:

      Set WhatForDlg = Utilities.NewControlBoxDialog
      WhatForDlg.Caption = “Create appointment”

      Set DateTime1 = WhatForDlg.AddDateTimeControl
      With DateTime1
      .Kind = fdtkTime
      .Time = iTimePeriodBegin
      .Caption = “Start Time:”
      End with

      Set DateTime2 = WhatForDlg.AddDateTimeControl
      With DateTime2
      .Kind = fdtkTime
      .Time = iTimePeriodEnd
      .Caption = “End Time:”
      End with

      This assumes that iTimePeriodBegin and iTimePeriodEnd are already defined. I want to adjust these using the dialog fields.

      Set objRecipient = objAppt.Recipients.Add(GroupWise.Account.Owner.EmailAddress,,0)
      With objAppt
      .StartDate = iTimePeriodBegin
      .EndDate = iTimePeriodEnd
      .Duration =
      End With

      Just doing this creates the appointment with the original times, not the updated times.

      The problem is that if I try .StartDate = DateTime1 (and .EndDate = DateTime2) then the result isn’t in the right format (and the applet errs out). Is there an easy way to convert the updated dialog datetime values into the right format for the appointment .StartDate and .EndDate ?

      Thanks!

    • Author
      Replies
    • #7909
      Support 1
      Participant

        >if I try .StartDate = DateTime1 (and .EndDate = DateTime2) then
        >the result isn’t in the right format (and the applet errs out)

        This will not work because the data type of DateTime1 and DateTime2 is DateTimePicker, whereas the data type of StartDate/EndDate is Date. See the Formativ Language Guide section on DateTimePicker and the GroupWise Object API documentation on Appointment.

        Assuming iTimePeriodBegin and iTimePeriodEnd are updated to match the values set by the user in the dialog box, it looks like your appointment’s times are only partially set. The Formativ Language Guide section on DateTimePicker indicates that its properties include Date as well as Time. From your code excerpt it is not clear that the value of Date is included in iTimePeriodBegin/iTimePeriodEnd. To combine the values of Date and Time, simply add them:

          with DateTime1
            iTimePeriodBegin = .Date + .Time
          end with
        

        I hope this helps.

        Regards,
        Advansys Support

        #7908
        dgerisch
        Participant

          That was exactly what I needed. Thank you! Smile

          #7915
          Support 3
          Participant

            Thanks for your feedback.

            You can also use the Formativ 2 to build custom forms and dialogs using the dynamic visual forms designer.

            Regards,
            Advansys Support

            #7914
            dgerisch
            Participant

              So I like the idea of using the visual forms designer, from some of the sample applications, it looks like I’m going to be able to get the fine-grained control I want. However, I’ve run into a slightly different problem now. With the old dialog, I was picking up date+times in a human-readable format, and using that for iTimePeriodBegin and iTimePeriodEnd.

              Now that I’m using the visual forms designer, I get errors about an OLE something and not a valid long number. Doing an export of the form to a file shows that the .Date data needs to be in the form of 39386.4694906366 (instead of 10/31/2007 11:54:00)

              Sure enough, plugging that real number into iTimePeriodBegin and iTimePeriodEnd lets the dialog display.

              What is the formula for computing this date+time number?

              -Or-

              Can I make the object DatePicker: TDateTimePicker be happy with a human readable date?

              Thanks!

              #7905
              Support 1
              Participant

                I don’t think it’s possible to assign a value like “10/31/3007” to DateTimePicker.Date, which is really a floating point number.

                Have you tried using the VBScript functions DateSerial(year, month, day) and TimeSerial(hour, minute, second)? You could use them to do something like:

                  DateTimePicker.DateTime = DateSerial(2007, 10, 31) + TimeSerial(11, 54, 0)
                

                Regards,
                Advansys Support

                #7911
                dgerisch
                Participant

                  It might be easier for me to compute the floating point number for DateTimePicker.Date than to parse the human readable string. (I’m not really a VBScript programmer). Is that number somthing like some-number-of-hours-since 1990?

                  The other possibility is just that I picked the wrong object type from the visual forms designer palette. I want the user to be able to use the equivalent of the classic Dlg.AddDateTimeControl

                  If I really had to, I could make my program (that is supplying me the time) output it in six different chunks like that so I wouldn’t have a big parsing job in front of me. But as long as I’m adapting that program, it might make sense to export the floating point number directly and just hand the dialog object the data it wants natively.

                  Thanks!

                  #7906
                  Support 1
                  Participant

                    I have generally found that it’s hard to write code that works with human-readable date/time values. When it’s necessary to record a date/time as a string, the UTC format is simple and easy to build or parse.

                    Why do you need to write code to work with the date/time in string form (human-readable or otherwise)? The reason I ask is for context; because there might be another way to solve the problem.

                    Regards,
                    Advansys Support

                    #7904
                    dgerisch
                    Participant

                      This Formativ applet that I’m building is essentially a one-button click to add a blog entry to a person’s calendar. It’s a little more than this, but at it’s core, this is it.

                      What I’m doing, is running a (small) program on the PC, that keeps track of the “last update” time. So every six minutes (although the user can specify thier own cycle duration), this program updates an .ini file on the PC.

                      This last update time is used by the Formativ applet as the (proposed) appointment.enddate

                      When the applet finishes, it updates the same .ini file – putting the appointment.enddate into the entry for the next cycle’s appointment.startdate

                      So I want to pull .startdate and .enddate from an .ini file, present them to the user (let the user modify the entries to his or her heart’s content), post the calendar item, and then write out the last .enddate to the .ini file to be used as the next .startdate

                      The program on the PC continues to run, waiting for time to pass, for the duration of the cycle. When the current cycle is over, it updates the .ini file again with the new appointment.enddate

                      Thus, every time you click the button to launch the Formativ applet, you get to add a posted appointment to your calendar – that picks up where the last entry left off. Of course, there are radio buttons that let you skip the appointment text (but still update the time), or specify that this time went toward a particular something. But those are user interface pieces I want to deal with later.

                      It is true that I do not need the .ini file entries to be in human readable format. It is a little nicer from a debugging stand point – but that is a minor issue.

                      Does this explain the goal I am trying to reach?

                      Thanks!

                      #7912
                      Support 3
                      Participant

                        If you want to store the date time value as human readable format then you need to make sure the format is convertible by your solution. Date format can vary by work-station where user can set different date format (yyyymmdd, ddmmyyyy, etc). You can use the Year(), Month(), Day(), etc method to extract the part of the date and save to the ini file. You program then need to read the part to convert to the exact date. For example:

                          
                           aDate = now
                           msgbox year(aDate) & month(aDate) & day(aDate) & hour(aDate) & minute(aDate) & second(aDate)
                        

                        Another approach which I will recommend to save the date as ISO format then your program can easily convert the ISO value from the ini file to date. You do not need to worry about the date format when saving as ISO format.

                          
                           iISODate = utilities.DateToISO(now)
                        
                           msgbox utilities.ISOToDate(iISODate)
                        
                        

                        Hope this helps.

                        Regards,
                        Advansys Support

                        #7900
                        dgerisch
                        Participant

                          Hmmm. I still have a problem. I have a form I created using the visual forms designer named “NewTimeRecord”

                          iTimePeriodBegin = utilities.DateToISO(now)
                          iTimePeriodEnd = utilities.DateToISO(now)

                          NewTimeRecord.DatePicker.Date = iTimePeriodEnd
                          NewTimeRecord.TimeBeginPicker.Date = iTimePeriodBegin
                          NewTimeRecord.TimeEndPicker.Date = iTimePeriodEnd

                          but the applet crashes on the third line, “NewTimeRecord.DatePicker.Date = iTimePeriodEnd”

                          EVariantTypeCastError
                          <path to>.vbf
                          Could not convert variant of type (OleStr) into type (Double) at line 17, column 5

                          #7910
                          Support 3
                          Participant

                            datetimepicker.Date() is a Read/Write property. You may only pass in a DATE to the property. Its returns a DATE.

                            Utilities.DateToISO() method convert Date to ISO value and return as string. In your code above you are trying to pass the string to the Date() property which accept DATE.

                            See the valid format where iISODate could be the Date value you read from the INI file:
                            NewTimeRecord.DatePicker.Date = utilities.ISOToDate(iISODate)

                            At the end of the process, save the date to INI file as ISO format:
                            utilities.DateToISO(datetimepicker.date)

                            Regards,
                            Advansys Support

                            #7907
                            dgerisch
                            Participant

                              So the good news is that this code runs without error:

                              isoTimePeriodBegin = objIniFile.ReadString(“Section”, “advTimePeriodBegin”, “”)
                              isoTimePeriodEnd = objIniFile.ReadString(“Section”, “advTimePeriodEnd”, “”)

                              datetimeTimePeriodBegin = Utilities.ISOToDate(isoTimePeriodBegin)
                              datetimeTimePeriodEnd = Utilities.ISOToDate(isoTimePeriodEnd)

                              NewTimeRecord.DatePicker.Date = datetimeTimePeriodEnd
                              NewTimeRecord.TimeBeginPicker.Date = datetimeTimePeriodBegin
                              NewTimeRecord.TimeEndPicker.Date = datetimeTimePeriodEnd

                              If NewTimeRecord.ShowModal() = mrOK Then

                              isoTimePeriodEnd = Utilities.DateToIso(NewTimeRecord.TimeEndPicker.Date)
                              isoTimePeriodBegin = objIniFile.WriteString(“Section”, “advTimePeriodBegin”, isoTimePeriodEnd)

                              End If

                              The bad news is that the form displays the time field from when the form was defined – not from datetimeTimePeriodBegin or datetimeTimePeriodEnd.

                              #7913
                              Support 3
                              Participant

                                Based on the code above, when the Form displayed first there was not date saved to the INI file.
                                isoTimePeriodBegin = objIniFile.ReadString(“Section”, “advTimePeriodBegin”, “”)

                                I think after the first execution the date value stored to the INI file so the subsequent execution you should see the correct date value.

                                Basically, isoTimePeriodEnd will be empty for the very first execution. You can add some defensive code so the isoTimePeriodEnd may be refer to the a date. Example:

                                  
                                if (len(isoTimePeriodEnd) = 0) then
                                  isoTimePeriodEnd = Utilities.DateToIso(Date-1)
                                end if
                                

                                Note, make sure you are saving the INI file to disk.

                                Regards,
                                Advansys Support

                                #7901
                                Support 1
                                Participant

                                  Further to Support 3’s comments, is your code assigning the appropriate value to the Time/DateTime (as opposed to the Date) property?

                                  For example:

                                    with NewTimeRecord
                                      .TimeBeginPicker.DateTime = datetimeTimePeriodBegin
                                      .TimeEndPicker.DateTime = datetimeTimePeriodEnd
                                    end

                                  Regards,
                                  Advansys Support

                                  #7902
                                  dgerisch
                                  Participant

                                    Sorry about the late reply – but yes, this was the info I needed. Thank you. 🙂

                                  Viewing 15 replies - 1 through 15 (of 16 total)
                                  • You must be logged in to reply to this topic.