Re: [Gambas-user] isNull()

2010-11-25 Thread Fabien Bodard
Le 25 novembre 2010 00:31, Benoît Minisini
gam...@users.sourceforge.net a écrit :
 I use IsNull extensively, is that going to be removed?

 richard


 No. I use it extensively too.

 Here is the result of my thought:

 - You can know the datatype of a variant with the TypeOf() function. You don't
 have to use the current Is() functions.

 - But you often need to know if a string can be converted to a number, an
 integer, a float, a date.

 - You normally want to know that for localized strings get from the outside
 (i.e. the user). For non-localized strings, they are intern to your program,
 so you should know what you are doing.

 So:

        IsNull(x) - kept its behaviour.
        IsInteger(x) - If Val(x) returns an integer
        IsFloat(x) - If Val(x) returns a float
        IsDate(x) - If Val(x) returns a date

hum ... isBinary ?

but how do you test if it's not ?

i imagine it is taht :

Function isFloat(Value as variant) as Float
dim fValue as Float

fValue = Val(Value)
if not error then return fValue


end


but in the other side i need to test it :/ again

if isFoat(Value) then print isFloat(Value)

in fact there is not fabulous soluce as we need two thing, known if a
convertion is possible with this datatype and then get the value.

the only one soluce i see is the C way... with a byref value

Function isFloat(Value as variant, Byref Ret as Float) as Boolean
dim fValue as Float

fValue = Val(Value)
if not error then
  Ret  = fValue
  Return True
endif

return

end

Dim fRet as Float

If IsFloat(Value, ByRef fRet) then Print fRet



 They should be enough. But I could add:

        IsLong(x) - If Val(x) returns a Long
        IsSingle(x) - If Single(x) returns a Single.

 Regards,

 --
 Benoît Minisini

 --
 Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
 Tap into the largest installed PC base  get more eyes on your game by
 optimizing for Intel(R) Graphics Technology. Get started today with the
 Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
 http://p.sf.net/sfu/intelisp-dev2dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user




-- 
Fabien Bodard

--
Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
Tap into the largest installed PC base  get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] isNull()

2010-11-25 Thread Bruce Bruen
On Thu, 25 Nov 2010 10:01:42 am Benoît Minisini wrote:
  I use IsNull extensively, is that going to be removed?
  
  richard
 
 No. I use it extensively too.
 
 Here is the result of my thought:
 
 - You can know the datatype of a variant with the TypeOf() function. You
 don't have to use the current Is() functions.
 
 - But you often need to know if a string can be converted to a number, an
 integer, a float, a date.
 
 - You normally want to know that for localized strings get from the outside
 (i.e. the user). For non-localized strings, they are intern to your
 program, so you should know what you are doing.
 
 So:
 
   IsNull(x) - kept its behaviour.
   IsInteger(x) - If Val(x) returns an integer
   IsFloat(x) - If Val(x) returns a float
   IsDate(x) - If Val(x) returns a date
 
 They should be enough. But I could add:
 
   IsLong(x) - If Val(x) returns a Long
   IsSingle(x) - If Single(x) returns a Single.
 
 Regards,
Benoît,

I would like to see the generic IsNumber retained.  When dealing with external 
data sources, i.e. data from an external system source not a user the 
content of data fields in a database can vary widely over time. In different 
eras, a particular column may have it's type changed in the source database 
system but the existent data remains undisturbed.

Although it sounds weird, we often see data columns on mainframe and even on 
some PC based rdbms that have gone from a text (or char or varchar) to a 
numeric type, to a different numeric type and so forth.  In these database 
systems, any new inserts or updates will conform to the current type 
definition.  However, existing data is left as is.

So if booktype was originally char(1), then became charvar then became a 
specific structured datatype (for example, some of the custom types provided 
for in postgresql), we still see instances of, say A being returned by the 
dbms for booktype.  (The way we handle this is by way of our own postgresql 
front end database that accesses the remote dbms and returns text fields for 
any and all columns that contain suspect data types.)

In the main, I don't care if the field contains an integer or a float (or a 
long or single etc) just that it contains a number and not any non-numeric 
data.  I will worry about the representation after I have determined that it 
is a number.

I realise that this is a fairly arcane use of gambas, but the speed that we 
can develop (and run) filters based on this approach is why I chose gambas in 
the first place.  As I said, we use a 80-20 rule to get to the core issue of 
the data as soon as possible.  The parsing filters get more and more complex 
for each 20% left over.   So the ability to recognise generic datatypes in 
string values, is it a number, good, then return true else start looking for 
other clues as to what it is supposed to represent ... does it look like it 
might be a date? If so then try to decipher the date structure, else does it 
look like a known construct (i.e IF wkstr LIKE *(*%)* then ...) etc etc.


Oh, and by the way, I too use IsNull extensively, specifically to provide 
lazy loads of subordinate persisted objects, usually collections, whose 
content is not required unless specifically accessed.  For example, a Book 
object may have a property which is an Author object.  When the persisted 
book object is loaded from the database, the author object is not loaded until 
the program actually accesses the book.author property, viz

PRIVATE FUNCTION MyAuthor() as Author
if IsNull($myAuthor) 
$myAuthor=NEW Author
$myAuthor.LoadDB(ME.AuthorName)
endif
RETURN $myAuthor
END

(obviously simplified to exclude error checking).

-- 
best regards
Bruce Bruen

--
Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
Tap into the largest installed PC base  get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] isNull()

2010-11-25 Thread Benoît Minisini
 On Thu, 25 Nov 2010 10:01:42 am Benoît Minisini wrote:
   I use IsNull extensively, is that going to be removed?
   
   richard
  
  No. I use it extensively too.
  
  Here is the result of my thought:
  
  - You can know the datatype of a variant with the TypeOf() function. You
  don't have to use the current Is() functions.
  
  - But you often need to know if a string can be converted to a number, an
  integer, a float, a date.
  
  - You normally want to know that for localized strings get from the
  outside (i.e. the user). For non-localized strings, they are intern to
  your program, so you should know what you are doing.
  
  So:
  IsNull(x) - kept its behaviour.
  IsInteger(x) - If Val(x) returns an integer
  IsFloat(x) - If Val(x) returns a float
  IsDate(x) - If Val(x) returns a date
  
  They should be enough. But I could add:
  IsLong(x) - If Val(x) returns a Long
  IsSingle(x) - If Single(x) returns a Single.
  
  Regards,
 
 Benoît,
 
 I would like to see the generic IsNumber retained.  When dealing with
 external data sources, i.e. data from an external system source not a
 user the content of data fields in a database can vary widely over time.
 In different eras, a particular column may have it's type changed in the
 source database system but the existent data remains undisturbed.
 
 Although it sounds weird, we often see data columns on mainframe and even
 on some PC based rdbms that have gone from a text (or char or varchar) to
 a numeric type, to a different numeric type and so forth.  In these
 database systems, any new inserts or updates will conform to the current
 type definition.  However, existing data is left as is.
 
 So if booktype was originally char(1), then became charvar then became a
 specific structured datatype (for example, some of the custom types
 provided for in postgresql), we still see instances of, say A being
 returned by the dbms for booktype.  (The way we handle this is by way of
 our own postgresql front end database that accesses the remote dbms and
 returns text fields for any and all columns that contain suspect data
 types.)
 
 In the main, I don't care if the field contains an integer or a float (or a
 long or single etc) just that it contains a number and not any non-numeric
 data.  I will worry about the representation after I have determined that
 it is a number.
 
 I realise that this is a fairly arcane use of gambas, but the speed that we
 can develop (and run) filters based on this approach is why I chose gambas
 in the first place.  As I said, we use a 80-20 rule to get to the core
 issue of the data as soon as possible.  The parsing filters get more and
 more complex for each 20% left over.   So the ability to recognise
 generic datatypes in string values, is it a number, good, then return
 true else start looking for other clues as to what it is supposed to
 represent ... does it look like it might be a date? If so then try to
 decipher the date structure, else does it look like a known construct
 (i.e IF wkstr LIKE *(*%)* then ...) etc etc.
 
 
 Oh, and by the way, I too use IsNull extensively, specifically to provide
 lazy loads of subordinate persisted objects, usually collections, whose
 content is not required unless specifically accessed.  For example, a
 Book object may have a property which is an Author object.  When the
 persisted book object is loaded from the database, the author object is
 not loaded until the program actually accesses the book.author property,
 viz
 
 PRIVATE FUNCTION MyAuthor() as Author
   if IsNull($myAuthor)
   $myAuthor=NEW Author
   $myAuthor.LoadDB(ME.AuthorName)
   endif
   RETURN $myAuthor
 END
 
 (obviously simplified to exclude error checking).

You must check the datatype of a column by using Result.Fields[xxx].Type, 
not by using Is() on the value. 

Or if really you don't want, use TypeOf().

Anyway, in my list, IsFloat() does what you want IsNumber() to do, as there is 
no number higher than Float in the Gambas number hierarchy.

Regards,

-- 
Benoît Minisini

--
Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
Tap into the largest installed PC base  get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] isNull()

2010-11-24 Thread richard terry
I use IsNull extensively, is that going to be removed?

richard

--
Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
Tap into the largest installed PC base  get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user