Hi, all
I tried to print out the PC date in the form, but I only got some unknown
symbols in the form instead of date. Anyone can tell me what's wrong with my
code ?

static Boolean datetime_handler(EventPtr event)
{
        FormPtr   form;
        UInt       handled = 0;
        UInt          index;
        VoidHand      RecHandle;
        Ptr           RecPointer;
//      time_t   systime;               // time data type
        Char      pString[dateStringLength];
        Word error = 0;
        Err err = 0;
        SystemPreferencesType  sysPrefs;
        DateTimeType  dateTime;
        DateFormatType dateFormat;
        Word year;
        Byte month;
        Byte day;
        
        form = FrmGetActiveForm();

        switch (event->eType) 
        {
        case frmOpenEvent:
                FrmDrawForm(form);
                handled = 1;
 
                        PrefGetPreferences (&sysPrefs);

                        //Get the time formats from the system preferences.
                        TimeFormat = sysPrefs.timeFormat;
 
                        //Get the date formats from the system preferences
                        LongDateFormat = sysPrefs.longDateFormat;
                        ShortDateFormat = sysPrefs.dateFormat;
                        
                        dateFormat = LongDateFormat;
                        
                        //Get today's date
                        TimSecondsToDateTime (TimGetSeconds (), &dateTime);
                        Date.year = dateTime.year - firstYear;
                        Date.month = dateTime.month;
                        Date.day = dateTime.day;
                        
                        year = Date.year;
                        month = Date.month;
                        day = Date.day;
                        
                        
                        DateToAscii(year,month,day,dateFormat,pString);
                
                // print the time to the PC time/date field
                fieldptr_datetime_date = FrmGetObjectPtr(form,
FrmGetObjectIndex(form, fieldID_datetime_date));
                FldSetTextPtr(fieldptr_datetime_date, pString);
                FldRecalculateField(fieldptr_datetime_date, true);
                
                break;
    
        case ctlSelectEvent:
                if (event->data.ctlEnter.controlID== buttonID_datetime_done)

                        {       
                // if user pushes the done button, return to comm form
                        FrmGotoForm(formID_comm);
                        handled = 1; 
                        
                }

                break;

        case frmCloseEvent:
                datetime_close();
                FrmHandleEvent(FrmGetActiveForm(), event);
                handled = 1;
                break;
    
                case nilEvent:
                handled = 1;
                break;

        
        }
        return handled;

}

Thank you for any help

Reply via email to