[Gambas-user] Maybe a bug with val functiun

Benoit Minisini gambas at ...2...
Mon Nov 10 09:18:01 CET 2003


Le Lundi 10 Novembre 2003 06:54, Olivier Coquet a écrit :
> Le Dimanche 9 Novembre 2003 18:37, Benoit Minisini a écrit :
> > Le Samedi 8 Novembre 2003 18:00, Olivier Coquet a écrit :
> > > PUBLIC FUNCTION dte_conv(dte AS String, rev AS Boolean) AS String
> > > ' Fonction de convertion de date, si rev = true format = bdd
> > > ' si rev = false format à la française
> > >   DIM m AS String
> > >   DIM j AS String
> > >   DIM y AS String
> > >
> > >   m=""
> > >   j=""
> > >   y=""
> > >
> > >   IF rev = FALSE THEN
> > >
> > >     j = Left$(dte,2)
> > >     m = Mid$(dte,4,2)
> > >     y = Right$(dte,2)
> > >
> > >       IF (Val(j) > 31) OR (Val(m) > 12)THEN
> > >         RETURN ("")
> > >       ELSE
> > >         RETURN (m & "-" & j & "-" & y)
> > >       ENDIF
> > >
> > >
> > >   ELSE
> > >
> > >     m = Left$(dte,2)
> > >     j = Mid$(dte,4,2)
> > >     y = Right$(dte,2)
> > >
> > >
> > >       IF (Val(j) > 31) OR (Val(m) > 12)THEN
> > >         RETURN ("")
> > >       ELSE
> > >         RETURN (j & "-" & m & "-" & y)
> > >       ENDIF
> > >
> > >
> > >
> > >   ENDIF
> > > END
> > >
> > > ........end of code
> > >
> > > Regards
> > > Olivier
> >
> > Hi, Olivier.
> >
> > It's a pity that you don't give me more details to reproduce the bug. See
> > my answer to Rob later too.
>
> try to call this function with arg="12.10.2003" an just after with arg
> ="aa.bb.cc"
>
> surprise !!!!! result will be: "bb.aa.cc"
>
> stop the prog
> try to call the function with arg = "aa.bb.cc" result will be an error
> !!!!!
>
> > Another point: if you want to start a new thread on the mailing-list,
> > DON'T reply to a previous post !
> >
> > Regards,
>
> regards
> olivier
>

OK, Olivier, I think I understood what happens !

The implementation of the comparison operators (>, <, >= and <=) is just bad. 
I will rewrite it in the next version so that:

"aaa" > NULL is equivalent to "aaa" > ""

34 > "33" raises an error. At the moment, 34 is automatically converted to 
"34".

The behaviour you pointed may be strange for you. Actually, the first time a 
code is executed, the interpreter sometimes optimizes it by registering 
operands datatypes. So is the comparison operators. And there was a bug in 
Val() that should have returned a Variant and didn't...

Well, some unexpected work for the next version :-) But thanks for having 
found this awful bug !

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...





More information about the User mailing list