[Gambas-user] More Date woes

Richard richard.j.walker at ...247...
Sat Mar 15 02:52:37 CET 2008


Le Friday 14 March 2008 09:01:12 Benoit Minisini, vous avez écrit :
> On vendredi 14 mars 2008, Richard wrote:
> > I have hit another snag with date handling while working on the problem
> > referred to above (see "Strange problem with Date Time and ValueBox").
> >
> > I use long form dates. I have done it for years. I like it that way.
> > Gambas2 does not provide a mechanism (that I can find) to specify a
> > default date format. When I set a ValueBox widget to display a date it is
> > Gambas that decides whether it should be 13/03/2008 or 13/03/08 which
> > seems to be governed by how I set the value.
> >
> > If I use:
> >
> >     StartDateBox.value = Now
> >
> > then I get a 4 digit year.
> >
> > If I use:
> >
> >     StartDateBox2.Value = Date(Now)
> >
> > then I get a 2 digit year.
>
> This is a bug in ValueBox that forgets to reformat its contents after the
> Value property is set.

Benoit, 
I had a look at the ValueBox and I reckon this might work. It certainly 
performs properly with the few tests I have had time to run;

PRIVATE SUB Value_Write(Value AS Variant)

  SELECT CASE TRUE
    
    CASE (TypeOf(Value) = gb.Float OR TypeOf(Value) = gb.Integer) AND (ME.Type 
= {Number})
      SUPER.Text = Str(Value)
      
    CASE (TypeOf(Value) = gb.Date) AND (ME.Type = {Date})
      SUPER.Text = Format(Value, $sDateFormat)

    CASE (TypeOf(Value) = gb.Date) AND (ME.Type = {Time})
      SUPER.Text = Format(Value, $sTimeFormat)

    CASE (TypeOf(Value) = gb.String) AND (ME.Type = {Identifier})
      SUPER.Text = Value

    CASE ELSE 
      SUPER.Text = Str(Value)
    
  END SELECT

END

If somebody manages to supply a value which doesn't fit one of the defined 
CASEs then it falls back to handling it just like the original. 

Do you have a test suite for this component I coud run against the modified 
version?

Richard

>
> > Does anyone know of a way to define a format for a ValueBox which will
> > work for both input and display?
> >
> > Richard
>
> There is no way at the moment to change the format used for displaying the
> ValueBox contents.
>
> Regards,






More information about the User mailing list