[Gambas-user] More Date woes

Richard richard.j.walker at ...247...
Fri Mar 14 18:44:02 CET 2008


Jeffrey, thanks for the reminder on Format/Format$. I don't think I have used 
it anywhere in the current version of my program. I may have to go back to 
it, or be more careful in how I derive the Date values I display in ValueBox 
widgets.


Benoit, perhaps I can do something useful if I study the ValueBox component. I 
learned a little bit from debugging an early version of DateBox and TimeBox 
and I have dared to tweak the DateChooser control to vary the format of the 
month name in the combo box depending on the width of the control.

The tweak works well in English where full month names have well defined 3 
letter short forms, and I use digits where even 3 letters is too long. 

If anyone is interested, the code is a simple form resize handler which can be 
added to the end of gambas/comp/src/gb.form/FCalendar.class. Here it is:

PUBLIC SUB Form_Resize()
DIM mth AS Integer
DIM mth_name_max_len, mth_name_len, n, cboxW AS Integer
DIM mth_format AS String

    'Get rid of all combo box strings
    cmbMonth.Clear

    'First find out the longest full month name
    ' 	The (-20) adjustment to width is an attempt to compensate for the 
    ' 	inclusion of the drop down button in the reported width of the control.
    cboxW = cmbMonth.Width - 20

    'Test for 4, 3 and 2 format characters ("m")
    FOR n = 4 TO 2 STEP -1
        mth_name_max_len = 0
        mth_format = String$(n, "m")
	'Check all month names
        FOR mth = 1 TO 12
            mth_name_len = cmbMonth.Font.Width(DConv(Format(Date(1972, mth, 
1), mth_format)))
            IF mth_name_len > mth_name_max_len THEN   
                mth_name_max_len = mth_name_len
            ENDIF 
        NEXT 

        'Next find out if the month name will fit the combo box
        IF mth_name_max_len <= cboxW THEN
            FOR mth = 1 TO 12
                cmbMonth.Add(DConv(Format(Date(1972, mth, 1), mth_format)))
            NEXT 
            BREAK 
        ENDIF 
    NEXT

END



Richard




More information about the User mailing list