Thread: [Gambas-user] Removing / Modifying IsXXXX() functions in Gambas 3
Brought to you by:
gambas
|
From: Benoît M. <ga...@us...> - 2010-11-24 11:08:46
|
Hi,
I'm currently thinking about modifying/removing all IsXXXX() functions in
Gambas 3.
They mainly test the datatype of their expression. So, either the datatype is
known at compile time, and there should be no need of testing it ; either you
are using a Variant, and you can use TypeOf() to get the datatype of the
value.
I will replace them by some functions that will test if a value can be
converted safely from a string by using localization. This is what most users
expected from these functions.
For exemple, in french localization:
IsDate("13/2/20") -> True
IsNumber("3,34") -> True
IsInteger("3,34") -> False
IsNumber("3.34") -> False
Internally, they will use Val() and see if the conversion works.
I will kept most of the name, so there will be a big incompatibility between
Gambas 2, current Gambas 3, and final Gambas 3.
What do you think about that?
Who is using the IsXXXX() functions, and in which context?
--
Benoît Minisini
|
|
From: Ron <ro...@cy...> - 2010-11-24 11:18:36
|
On 24-11-2010 12:08, Benoît Minisini wrote:
> Hi,
>
> I'm currently thinking about modifying/removing all IsXXXX() functions in
> Gambas 3.
>
> They mainly test the datatype of their expression. So, either the datatype is
> known at compile time, and there should be no need of testing it ; either you
> are using a Variant, and you can use TypeOf() to get the datatype of the
> value.
>
> I will replace them by some functions that will test if a value can be
> converted safely from a string by using localization. This is what most users
> expected from these functions.
>
> For exemple, in french localization:
>
> IsDate("13/2/20") -> True
> IsNumber("3,34") -> True
> IsInteger("3,34") -> False
> IsNumber("3.34") -> False
>
> Internally, they will use Val() and see if the conversion works.
>
> I will kept most of the name, so there will be a big incompatibility between
> Gambas 2, current Gambas 3, and final Gambas 3.
>
> What do you think about that?
>
> Who is using the IsXXXX() functions, and in which context?
>
I use these in my project, a lot less than expected at first:
Bluetooth.module: IF IsInteger(Val(sRSSI)) THEN
Bluetooth.module: iRSSI = IsInteger(Val(sRSSI))
Events.module: IF rResult!rerunenabled = TRUE AND IF
IsDate(rResult!lastrun) THEN
Events.module: IF IsBoolean(sValue) THEN sValue = Main.DisplayBool(sValue)
Events.module: IF IsBoolean(sCond) THEN sCond = Main.DisplayBool(sCond)
Events.module: ELSE IF IsBoolean(vResult) THEN
JSON.module: IF NOT IsLetter(sCar) THEN RETURN sCar
JSON.module: IF NOT IsLetter(sCar) THEN
JSON.module: IF IsNull(vNumber) THEN Error.Raise("Incorrect number")
JSON.module: ELSE IF sCar = "-" OR IF IsDigit(sCar) THEN
Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN
Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"])
Main.module: IF NOT IsNull(vValue) THEN
Main.module: IF IsNumber(Val(tv[k, col].Text)) THEN
Main.module: IF IsNumber(Val(gv[k, col].Text)) THEN
Main.module:PUBLIC FUNCTION IsTime(sString AS String) AS Boolean
Main.module:PUBLIC FUNCTION IsBool(sStr AS String) AS Boolean
CDenon.class: IF IsInteger(sValue) THEN
CDenon.class: IF IsInteger(sValue) THEN
CDenon.class: IF IsNull(Val(sZonecat)) THEN
CRFXComRX.class: IF IsDigit(Hex(RecBuf[4])) AND IF
IsDigit(Hex(Lsr(RecBuf[3], 4))) THEN
CSqueezeServer.class: ELSE IF IsLetter(sCar) OR IF IsDigit(sCar) OR
IF InStr("*-._", sCar) THEN
FConditionEditor.class: IF NOT
(Main.IsBool(Events.EvalFormula(taFormula.Text))) THEN
FConditionEditor.class: IF IsBoolean(vVal) THEN
FDebug.class: IF IsBoolean(vValue) THEN
FTriggerEditor.class: IF IsBoolean(Main.GlobalVar[cmbVariables.Text])
THEN
FTriggerEditor.class: ELSE IF NOT
IsNumber(Main.GlobalVar[cmbVariables.Text]) THEN
FTriggerEditor.class: IF IsNumber(Val(txtDeviceValue.Text)) THEN
Regards,
Ron_2nd.
|
|
From: Benoît M. <ga...@us...> - 2010-11-24 11:28:13
|
> On 24-11-2010 12:08, Benoît Minisini wrote:
> > Hi,
> >
> > I'm currently thinking about modifying/removing all IsXXXX() functions in
> > Gambas 3.
> >
> > They mainly test the datatype of their expression. So, either the
> > datatype is known at compile time, and there should be no need of
> > testing it ; either you are using a Variant, and you can use TypeOf() to
> > get the datatype of the value.
> >
> > I will replace them by some functions that will test if a value can be
> > converted safely from a string by using localization. This is what most
> > users expected from these functions.
> >
> > For exemple, in french localization:
> > IsDate("13/2/20") -> True
> > IsNumber("3,34") -> True
> > IsInteger("3,34") -> False
> > IsNumber("3.34") -> False
> >
> > Internally, they will use Val() and see if the conversion works.
> >
> > I will kept most of the name, so there will be a big incompatibility
> > between Gambas 2, current Gambas 3, and final Gambas 3.
> >
> > What do you think about that?
> >
> > Who is using the IsXXXX() functions, and in which context?
>
> I use these in my project, a lot less than expected at first:
>
> Bluetooth.module: IF IsInteger(Val(sRSSI)) THEN
> Bluetooth.module: iRSSI = IsInteger(Val(sRSSI))
> Events.module: IF rResult!rerunenabled = TRUE AND IF
> IsDate(rResult!lastrun) THEN
> Events.module: IF IsBoolean(sValue) THEN sValue = Main.DisplayBool(sValue)
> Events.module: IF IsBoolean(sCond) THEN sCond = Main.DisplayBool(sCond)
> Events.module: ELSE IF IsBoolean(vResult) THEN
> JSON.module: IF NOT IsLetter(sCar) THEN RETURN sCar
> JSON.module: IF NOT IsLetter(sCar) THEN
> JSON.module: IF IsNull(vNumber) THEN Error.Raise("Incorrect number")
> JSON.module: ELSE IF sCar = "-" OR IF IsDigit(sCar) THEN
> Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN
> Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"])
> Main.module: IF NOT IsNull(vValue) THEN
> Main.module: IF IsNumber(Val(tv[k, col].Text)) THEN
> Main.module: IF IsNumber(Val(gv[k, col].Text)) THEN
> Main.module:PUBLIC FUNCTION IsTime(sString AS String) AS Boolean
> Main.module:PUBLIC FUNCTION IsBool(sStr AS String) AS Boolean
> CDenon.class: IF IsInteger(sValue) THEN
> CDenon.class: IF IsInteger(sValue) THEN
> CDenon.class: IF IsNull(Val(sZonecat)) THEN
> CRFXComRX.class: IF IsDigit(Hex(RecBuf[4])) AND IF
> IsDigit(Hex(Lsr(RecBuf[3], 4))) THEN
> CSqueezeServer.class: ELSE IF IsLetter(sCar) OR IF IsDigit(sCar) OR
> IF InStr("*-._", sCar) THEN
> FConditionEditor.class: IF NOT
> (Main.IsBool(Events.EvalFormula(taFormula.Text))) THEN
> FConditionEditor.class: IF IsBoolean(vVal) THEN
> FDebug.class: IF IsBoolean(vValue) THEN
> FTriggerEditor.class: IF IsBoolean(Main.GlobalVar[cmbVariables.Text])
> THEN
> FTriggerEditor.class: ELSE IF NOT
> IsNumber(Main.GlobalVar[cmbVariables.Text]) THEN
> FTriggerEditor.class: IF IsNumber(Val(txtDeviceValue.Text)) THEN
>
> Regards,
> Ron_2nd.
>
When you do IsNumber(Val(...)), you actually want the new behaviour I want to
implement: checking if a string can be safely converted to what you want. In
the new syntax, you will directly do IsNumber(...).
The IsDigit(), IsLetter()... functions are not concerned by the change.
IsNull() will be kept unchanged.
Then, please tell me what you are testing exactly with these lines:
Events.module: IF rResult!rerunenabled = TRUE AND IF
IsDate(rResult!lastrun) THEN
Events.module: IF IsBoolean(sValue) THEN sValue = Main.DisplayBool(sValue)
Events.module: IF IsBoolean(sCond) THEN sCond = Main.DisplayBool(sCond)
Events.module: ELSE IF IsBoolean(vResult) THEN
Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN
Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"])
CDenon.class: IF IsInteger(sValue) THEN
CDenon.class: IF IsInteger(sValue) THEN
FConditionEditor.class: IF IsBoolean(vVal) THEN
FDebug.class: IF IsBoolean(vValue) THEN
FTriggerEditor.class: IF IsBoolean(Main.GlobalVar[cmbVariables.Text])
THEN
FTriggerEditor.class: ELSE IF NOT
IsNumber(Main.GlobalVar[cmbVariables.Text]) THEN
Thanks in advance.
--
Benoît Minisini
|
|
From: Ron <ro...@cy...> - 2010-11-24 12:10:58
|
On 24-11-2010 12:28, Benoît Minisini wrote:
>> On 24-11-2010 12:08, Benoît Minisini wrote:
>>> Hi,
>>>
>>> I'm currently thinking about modifying/removing all IsXXXX() functions in
>>> Gambas 3.
>>>
>>> They mainly test the datatype of their expression. So, either the
>>> datatype is known at compile time, and there should be no need of
>>> testing it ; either you are using a Variant, and you can use TypeOf() to
>>> get the datatype of the value.
>>>
>>> I will replace them by some functions that will test if a value can be
>>> converted safely from a string by using localization. This is what most
>>> users expected from these functions.
>>>
>>> For exemple, in french localization:
>>> IsDate("13/2/20") -> True
>>> IsNumber("3,34") -> True
>>> IsInteger("3,34") -> False
>>> IsNumber("3.34") -> False
>>>
>>> Internally, they will use Val() and see if the conversion works.
>>>
>>> I will kept most of the name, so there will be a big incompatibility
>>> between Gambas 2, current Gambas 3, and final Gambas 3.
>>>
>>> What do you think about that?
>>>
>>> Who is using the IsXXXX() functions, and in which context?
>> I use these in my project, a lot less than expected at first:
>>
>> Bluetooth.module: IF IsInteger(Val(sRSSI)) THEN
>> Bluetooth.module: iRSSI = IsInteger(Val(sRSSI))
>> Events.module: IF rResult!rerunenabled = TRUE AND IF
>> IsDate(rResult!lastrun) THEN
>> Events.module: IF IsBoolean(sValue) THEN sValue = Main.DisplayBool(sValue)
>> Events.module: IF IsBoolean(sCond) THEN sCond = Main.DisplayBool(sCond)
>> Events.module: ELSE IF IsBoolean(vResult) THEN
>> JSON.module: IF NOT IsLetter(sCar) THEN RETURN sCar
>> JSON.module: IF NOT IsLetter(sCar) THEN
>> JSON.module: IF IsNull(vNumber) THEN Error.Raise("Incorrect number")
>> JSON.module: ELSE IF sCar = "-" OR IF IsDigit(sCar) THEN
>> Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN
>> Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"])
>> Main.module: IF NOT IsNull(vValue) THEN
>> Main.module: IF IsNumber(Val(tv[k, col].Text)) THEN
>> Main.module: IF IsNumber(Val(gv[k, col].Text)) THEN
>> Main.module:PUBLIC FUNCTION IsTime(sString AS String) AS Boolean
>> Main.module:PUBLIC FUNCTION IsBool(sStr AS String) AS Boolean
>> CDenon.class: IF IsInteger(sValue) THEN
>> CDenon.class: IF IsInteger(sValue) THEN
>> CDenon.class: IF IsNull(Val(sZonecat)) THEN
>> CRFXComRX.class: IF IsDigit(Hex(RecBuf[4])) AND IF
>> IsDigit(Hex(Lsr(RecBuf[3], 4))) THEN
>> CSqueezeServer.class: ELSE IF IsLetter(sCar) OR IF IsDigit(sCar) OR
>> IF InStr("*-._", sCar) THEN
>> FConditionEditor.class: IF NOT
>> (Main.IsBool(Events.EvalFormula(taFormula.Text))) THEN
>> FConditionEditor.class: IF IsBoolean(vVal) THEN
>> FDebug.class: IF IsBoolean(vValue) THEN
>> FTriggerEditor.class: IF IsBoolean(Main.GlobalVar[cmbVariables.Text])
>> THEN
>> FTriggerEditor.class: ELSE IF NOT
>> IsNumber(Main.GlobalVar[cmbVariables.Text]) THEN
>> FTriggerEditor.class: IF IsNumber(Val(txtDeviceValue.Text)) THEN
>>
>> Regards,
>> Ron_2nd.
>>
> When you do IsNumber(Val(...)), you actually want the new behaviour I want to
> implement: checking if a string can be safely converted to what you want. In
> the new syntax, you will directly do IsNumber(...).
>
> The IsDigit(), IsLetter()... functions are not concerned by the change.
>
> IsNull() will be kept unchanged.
>
> Then, please tell me what you are testing exactly with these lines:
>
> Events.module: IF rResult!rerunenabled = TRUE AND IF
> IsDate(rResult!lastrun) THEN
It appears to be just a test if the db record field has a date value in
it, instead of an empty value.
> Events.module: IF IsBoolean(sValue) THEN sValue = Main.DisplayBool(sValue)
> Events.module: IF IsBoolean(sCond) THEN sCond = Main.DisplayBool(sCond)
> Events.module: ELSE IF IsBoolean(vResult) THEN
---
PUBLIC SUB CheckCondition(sValue AS Variant, sOperand AS String, sCond
AS Variant, OPTIONAL bMute AS Boolean) AS Boolean
DIM bReturn AS Boolean
IF IsBoolean(sValue) THEN sValue = Main.DisplayBool(sValue)
IF IsBoolean(sCond) THEN sCond = Main.DisplayBool(sCond)
---
CheckConditions(), has variants as arguments.
If the variant sValue is a Boolean, then change it to a string value
with "True" "False" as content, so that conversion and compare tests
(below) after that can be more generic.
---
SELECT sOperand
CASE "="
IF Comp(sValue, sCond) = 0 THEN bReturn = TRUE
CASE "<>"
IF sValue <> sCond THEN bReturn = TRUE
CASE ">"
IF CFloat(Replace(sValue, ",", ".", gb.String)) >
CFloat(Replace(sCond, ",", ".", gb.String)) THEN bReturn = TRUE
CASE "<"
IF CFloat(Replace(sValue, ",", ".", gb.String)) <
CFloat(Replace(sCond, ",", ".", gb.String)) THEN bReturn = TRUE
CASE ELSE
IF Main.bEventsDebug THEN Main.WriteDebugLog(("[Events] 2c.
Unsupported operand '" & sOperand & "' found!"))
END SELECT
IF Main.bEventsDebug AND IF NOT bMute THEN
Main.WriteDebugLog(("[Events] 2c. Check condition '") & sValue & " " &
sOperand & " " & sCond & "' = " & Main.DisplayBool(bReturn))
RETURN bReturn
CATCH
IF Main.bEventsDebug THEN Main.WriteDebugLog(("[Events] 2c. Invalid
comparison in CheckCondition() routine!"))
RETURN FALSE
END
---
> Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN
> Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"])
Just seems to be checks to see if the variant value from that collection
isn't empty, to prevent errors.
> CDenon.class: IF IsInteger(sValue) THEN
> CDenon.class: IF IsInteger(sValue) THEN
TRY sValue = Val(sValue)
IF IsInteger(sValue) THEN
sValue = sValue + 80
ELSE
IF UCase(sValue) = "OFF" THEN sValue = 99
ENDIF
To see if sValue contains a decibel value -18...80 , or on/off/up/down.
> FConditionEditor.class: IF IsBoolean(vVal) THEN
TRY vVal = Main.GlobalVar[Right(tvVariables.Current.Key,
Len(tvVariables.Current.Key) - 4)]
IF IsBoolean(vVal) THEN
sVal = Main.DisplayBool(vVal)
ELSE
sVal = vVal
ENDIF
vVal can be strings, numbers or booleans, if its a boolean, change it to
"True", "False", otherwise just a T or nothing is shown in TableView.
> FDebug.class: IF IsBoolean(vValue) THEN
Same here.
> FTriggerEditor.class: IF IsBoolean(Main.GlobalVar[cmbVariables.Text])
> THEN
> FTriggerEditor.class: ELSE IF NOT
> IsNumber(Main.GlobalVar[cmbVariables.Text]) THEN
>
If value is a boolean, disable compare checkboxes <, > , on form, just
have = and <> enabled, if it's a number allow, < and > too as operand
for trigger rules in my event/trigger editor.
Regards,
Ron_2nd.
|
|
From: Benoît M. <ga...@us...> - 2010-11-29 17:38:39
|
> >
> > When you do IsNumber(Val(...)), you actually want the new behaviour I
> > want to implement: checking if a string can be safely converted to what
> > you want. In the new syntax, you will directly do IsNumber(...).
> >
> > The IsDigit(), IsLetter()... functions are not concerned by the change.
> >
> > IsNull() will be kept unchanged.
> >
> > Then, please tell me what you are testing exactly with these lines:
> >
> > Events.module: IF rResult!rerunenabled = TRUE AND IF
> > IsDate(rResult!lastrun) THEN
>
> It appears to be just a test if the db record field has a date value in
> it, instead of an empty value.
>
If rResult!lastrun is a database date field, then you must replace IsDate(...)
par Not IsNull(...).
If rResult!lastrun is not a date field, then IsDate() was always returning
False, so now it will works as expected.
> > Events.module: IF IsBoolean(sValue) THEN sValue =
> > Main.DisplayBool(sValue) Events.module: IF IsBoolean(sCond) THEN sCond
> > = Main.DisplayBool(sCond) Events.module: ELSE IF IsBoolean(vResult)
> > THEN
>
> ---
> PUBLIC SUB CheckCondition(sValue AS Variant, sOperand AS String, sCond
> AS Variant, OPTIONAL bMute AS Boolean) AS Boolean
>
> DIM bReturn AS Boolean
>
> IF IsBoolean(sValue) THEN sValue = Main.DisplayBool(sValue)
> IF IsBoolean(sCond) THEN sCond = Main.DisplayBool(sCond)
> ---
>
> CheckConditions(), has variants as arguments.
> If the variant sValue is a Boolean, then change it to a string value
> with "True" "False" as content, so that conversion and compare tests
> (below) after that can be more generic.
>
You must replace all "IsBoolean(x)" by "TypeOf(x) = gb.Boolean". Same remark
actually for IsShort(), IsInteger(), IsFloat(), IsDate() and IsObject().
> ---
> SELECT sOperand
> CASE "="
> IF Comp(sValue, sCond) = 0 THEN bReturn = TRUE
> CASE "<>"
> IF sValue <> sCond THEN bReturn = TRUE
> CASE ">"
> IF CFloat(Replace(sValue, ",", ".", gb.String)) >
> CFloat(Replace(sCond, ",", ".", gb.String)) THEN bReturn = TRUE
> CASE "<"
> IF CFloat(Replace(sValue, ",", ".", gb.String)) <
> CFloat(Replace(sCond, ",", ".", gb.String)) THEN bReturn = TRUE
> CASE ELSE
> IF Main.bEventsDebug THEN Main.WriteDebugLog(("[Events] 2c.
> Unsupported operand '" & sOperand & "' found!"))
> END SELECT
> IF Main.bEventsDebug AND IF NOT bMute THEN
> Main.WriteDebugLog(("[Events] 2c. Check condition '") & sValue & " " &
> sOperand & " " & sCond & "' = " & Main.DisplayBool(bReturn))
> RETURN bReturn
>
> CATCH
> IF Main.bEventsDebug THEN Main.WriteDebugLog(("[Events] 2c. Invalid
> comparison in CheckCondition() routine!"))
> RETURN FALSE
>
> END
> ---
>
> > Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN
> > Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"])
>
> Just seems to be checks to see if the variant value from that collection
> isn't empty, to prevent errors.
So use 'Not IsNull()' instead.
>
> > CDenon.class: IF IsInteger(sValue) THEN
> > CDenon.class: IF IsInteger(sValue) THEN
>
> TRY sValue = Val(sValue)
> IF IsInteger(sValue) THEN
> sValue = sValue + 80
> ELSE
> IF UCase(sValue) = "OFF" THEN sValue = 99
> ENDIF
>
> To see if sValue contains a decibel value -18...80 , or on/off/up/down.
Now IsInteger() really tests if a string can be converted to an integer.
But the simpler is replacing IsInteger(sValue) by TypeOf(sValue) = gb.Integer.
>
> > FConditionEditor.class: IF IsBoolean(vVal) THEN
>
> TRY vVal = Main.GlobalVar[Right(tvVariables.Current.Key,
> Len(tvVariables.Current.Key) - 4)]
> IF IsBoolean(vVal) THEN
> sVal = Main.DisplayBool(vVal)
> ELSE
> sVal = vVal
> ENDIF
>
> vVal can be strings, numbers or booleans, if its a boolean, change it to
> "True", "False", otherwise just a T or nothing is shown in TableView.
Use "TypeOf(vVal) = gb.Boolean".
>
> > FDebug.class: IF IsBoolean(vValue) THEN
>
> Same here.
>
Same change.
> > FTriggerEditor.class: IF IsBoolean(Main.GlobalVar[cmbVariables.Text])
> > THEN
> > FTriggerEditor.class: ELSE IF NOT
> > IsNumber(Main.GlobalVar[cmbVariables.Text]) THEN
>
> If value is a boolean, disable compare checkboxes <, > , on form, just
> have = and <> enabled, if it's a number allow, < and > too as operand
> for trigger rules in my event/trigger editor.
You must replace "IsNumber(...)" by "TypeOf(...) > gb.Boolean And TypeOf(...)
<= gb.Float" (i.e. check the type of the variant against all possible number
datatypes).
Regards,
--
Benoît Minisini
|
|
From: Benoît M. <ga...@us...> - 2010-11-24 11:32:38
|
> On Wednesday 24 November 2010 22:08:34 Benoît Minisini wrote: > > Hi Benoit I use isDate() quite a lot, isNumber I think once > > Regards > richard > In which context exactly? -- Benoît Minisini |
|
From: Bruce B. <bb...@pa...> - 2010-11-24 13:11:21
|
On Wed, 24 Nov 2010 09:38:34 pm Benoît Minisini wrote:
> Hi,
>
> I'm currently thinking about modifying/removing all IsXXXX() functions in
> Gambas 3.
>
> They mainly test the datatype of their expression. So, either the datatype
> is known at compile time, and there should be no need of testing it ;
> either you are using a Variant, and you can use TypeOf() to get the
> datatype of the value.
>
> I will replace them by some functions that will test if a value can be
> converted safely from a string by using localization. This is what most
> users expected from these functions.
>
> For exemple, in french localization:
>
> IsDate("13/2/20") -> True
> IsNumber("3,34") -> True
> IsInteger("3,34") -> False
> IsNumber("3.34") -> False
>
> Internally, they will use Val() and see if the conversion works.
>
> I will kept most of the name, so there will be a big incompatibility
> between Gambas 2, current Gambas 3, and final Gambas 3.
>
> What do you think about that?
>
> Who is using the IsXXXX() functions, and in which context?
Benoît,
MAJOR PANIC! I use IsNumber extensively to do quick checks on field parsing
across heterogeneous databases. Using the 80-20 rule I can parse text fields
for junk appendices to an expected numeric.
Code such as
vItem=split(result!note," ",NULL,TRUE)[0]
IF IsNumber(vItem) THEN RETURN Val(vItem)
' else begin parsing diabolical note structure
.....
abounds.
Please reconsider this.
--
best regards
Bruce Bruen
|
|
From: Benoît M. <ga...@us...> - 2010-11-24 13:23:33
|
> > Benoît, > > MAJOR PANIC! I use IsNumber extensively to do quick checks on field > parsing across heterogeneous databases. Using the 80-20 rule I can parse > text fields for junk appendices to an expected numeric. > Code such as > > vItem=split(result!note," ",NULL,TRUE)[0] > IF IsNumber(vItem) THEN RETURN Val(vItem) > ' else begin parsing diabolical note structure > ..... > > abounds. > > Please reconsider this. Then you are using IsNumber() the wrong way: in your code, vItem is a string (I guess), and so IsNumber(vItem) will always return FALSE. You used IsNumber() as if it would tell you if a string can be converted to a number, which it does not at the moment! And which is exactly what I want to change! -- Benoît Minisini |
|
From: Rolf-Werner E. <eil...@t-...> - 2010-11-24 15:12:59
|
Am 24.11.2010 12:08, schrieb Benoît Minisini:
> Hi,
>
> I'm currently thinking about modifying/removing all IsXXXX() functions in
> Gambas 3.
>
> They mainly test the datatype of their expression. So, either the datatype is
> known at compile time, and there should be no need of testing it ; either you
> are using a Variant, and you can use TypeOf() to get the datatype of the
> value.
>
> I will replace them by some functions that will test if a value can be
> converted safely from a string by using localization. This is what most users
> expected from these functions.
>
> For exemple, in french localization:
>
> IsDate("13/2/20") -> True
> IsNumber("3,34") -> True
> IsInteger("3,34") -> False
> IsNumber("3.34") -> False
>
> Internally, they will use Val() and see if the conversion works.
>
> I will kept most of the name, so there will be a big incompatibility between
> Gambas 2, current Gambas 3, and final Gambas 3.
>
> What do you think about that?
>
> Who is using the IsXXXX() functions, and in which context?
>
I just checked it. As far as I remember and due to my search within my
most important projects, I have only used IsNull so far.
In one project, I used it very often to manage Val() because Val()
doesn't understand empty strings or strings without numbers. Wasn't it
you or Fabien who once pointed me to this fact and gave me the tip to
use IsNull for it?
In that project there are lots of places where wrong inputs could occur,
so there are lots of IF IsNull(bla) THEN RETURN "bullshit" or IF NOT
IsNull(bla) THEN RETURN Val(bla) ;-)
So from my point of view, if you let be Val() less critical, you my
discard IsNull, otherwise leave it there or replace it by something useful.
Regards
Rolf
|
|
From: <mat...@t-...> - 2010-11-24 19:54:52
|
If I understand you right,
If Not IsDigit(TextBox.Text) Then...
wouldn't be changed?
-----Original-Nachricht-----
Subject: [Gambas-user] Removing / Modifying IsXXXX() functions in Gambas 3
Date: Wed, 24 Nov 2010 12:08:34 +0100
From: Benoît Minisini <ga...@us...>
To: gam...@li...
Who is using the IsXXXX() functions, and in which context?
|
|
From: Benoît M. <ga...@us...> - 2010-11-24 22:53:12
|
> If I understand you right, > If Not IsDigit(TextBox.Text) Then... > wouldn't be changed? No. All IsXXX() functions that just test characters won't be changed. -- Benoît Minisini |
|
From: richard t. <rt...@pa...> - 2010-11-24 21:40:42
|
On Wednesday 24 November 2010 22:32:26 Benoît Minisini wrote: > > On Wednesday 24 November 2010 22:08:34 Benoît Minisini wrote: > > > > Hi Benoit I use isDate() quite a lot, isNumber I think once > > > > Regards > > richard > > In which context exactly? > When I've got textboxes and user has entered what is meant to be a date, for example on the lost_focus event |
|
From: Benoît M. <ga...@us...> - 2010-11-24 22:52:42
|
> On Wednesday 24 November 2010 22:32:26 Benoît Minisini wrote: > > > On Wednesday 24 November 2010 22:08:34 Benoît Minisini wrote: > > > > > > Hi Benoit I use isDate() quite a lot, isNumber I think once > > > > > > Regards > > > richard > > > > In which context exactly? > > When I've got textboxes and user has entered what is meant to be a date, > for example on the lost_focus event > I mean which code. IsDate() only tells you if a variant is a Date. If you want to check that a string is a date, you have to do that: dDate = Val(sTextBoxString) If IsNull(dDate) Then Print "Enter a date!" Endif -- Benoît Minisini |
|
From: Michael <mda...@tp...> - 2010-11-24 23:24:13
|
Benoit,
The IsXXX functions confused me because when testing IsNumber("123") I
got an error similar to "Expected number got a string". It seems you
needed to know the type before testing for it. I therefore do not use
it. However I believe new versions of software should be backward
compatible so I suggest giving the new functions a slightly different
name. EG: IsNumeric.
Regards
Mike
On 24/11/10 22:08, Benoît Minisini wrote:
> Hi,
>
> I'm currently thinking about modifying/removing all IsXXXX() functions in
> Gambas 3.
>
> They mainly test the datatype of their expression. So, either the datatype is
> known at compile time, and there should be no need of testing it ; either you
> are using a Variant, and you can use TypeOf() to get the datatype of the
> value.
>
> I will replace them by some functions that will test if a value can be
> converted safely from a string by using localization. This is what most users
> expected from these functions.
>
> For exemple, in french localization:
>
> IsDate("13/2/20") -> True
> IsNumber("3,34") -> True
> IsInteger("3,34") -> False
> IsNumber("3.34") -> False
>
> Internally, they will use Val() and see if the conversion works.
>
> I will kept most of the name, so there will be a big incompatibility between
> Gambas 2, current Gambas 3, and final Gambas 3.
>
> What do you think about that?
>
> Who is using the IsXXXX() functions, and in which context?
>
|
|
From: Benoît M. <ga...@us...> - 2010-11-24 23:33:45
|
> Benoit,
> The IsXXX functions confused me because when testing IsNumber("123") I
> got an error similar to "Expected number got a string". It seems you
> needed to know the type before testing for it.
Yes. Not really useful, except with variants.
> I therefore do not use
> it. However I believe new versions of software should be backward
> compatible so I suggest giving the new functions a slightly different
> name. EG: IsNumeric.
> Regards
> Mike
>
I think I can be not backward compatible there, because nobody apparently uses
this useless function. I don't want to keep these useless functions in the
interpreter.
Regards,
--
Benoît Minisini
|
|
From: Ron <ro...@cy...> - 2010-11-30 08:05:05
|
>>> Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN >>> Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"]) >> Just seems to be checks to see if the variant value from that collection >> isn't empty, to prevent errors. > So use 'Not IsNull()' instead. > I get when I do If Not IsNull(Main.GlobalVar["Minute"]) Then .... Error: Type Mismatch wanted string, got integer. Main.GlobalVar["Minute"] 's value is 34 Main.GlobalVar[] is a Collection with Variants , so contains all types of values. Sometimes, (don't know why) Main.GlobalVar["Minute"] contained a string so "34" instead of an integer, then further down my program things went wrong, so therefor this stupid check and correction posted above was used.. Regards, Ron_2nd. |
|
From: Benoît M. <ga...@us...> - 2010-11-30 11:58:42
|
> >>> Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN > >>> Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"]) > >> > >> Just seems to be checks to see if the variant value from that collection > >> isn't empty, to prevent errors. > > > > So use 'Not IsNull()' instead. > > I get when I do If Not IsNull(Main.GlobalVar["Minute"]) Then .... > > Error: Type Mismatch wanted string, got integer. > > Main.GlobalVar["Minute"] 's value is 34 > > Main.GlobalVar[] is a Collection with Variants , so contains all types > of values. > > Sometimes, (don't know why) Main.GlobalVar["Minute"] contained a string > so "34" instead of an integer, then further down my program things went > wrong, so therefor this stupid check and correction posted above was used.. > > Regards, > Ron_2nd. > Then you must do "If TypeOf(Main.GlobalVar["Minute"]) = gb.String" if you really need a string. Regardsn -- Benoît Minisini |
|
From: B. J. <gau...@ho...> - 2010-11-30 08:50:19
|
Perhaps GAMBAS needs something like Python's <string> y=repr(<any> x) to guarantee y is a string representation of x > Date: Tue, 30 Nov 2010 09:04:58 +0100 > From: ro...@cy... > To: gam...@li... > Subject: Re: [Gambas-user] Removing / Modifying IsXXXX() functions in Gambas3 > > > >>> Mail.module: IF IsString(Main.GlobalVar["Minute"]) THEN > >>> Main.GlobalVar["Minute"] = Val(Main.GlobalVar["Minute"]) > >> Just seems to be checks to see if the variant value from that collection > >> isn't empty, to prevent errors. > > So use 'Not IsNull()' instead. > > > > I get when I do If Not IsNull(Main.GlobalVar["Minute"]) Then .... > > Error: Type Mismatch wanted string, got integer. > > Main.GlobalVar["Minute"] 's value is 34 > > Main.GlobalVar[] is a Collection with Variants , so contains all types > of values. > > Sometimes, (don't know why) Main.GlobalVar["Minute"] contained a string > so "34" instead of an integer, then further down my program things went > wrong, so therefor this stupid check and correction posted above was used.. > > Regards, > Ron_2nd. > > ------------------------------------------------------------------------------ > 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 > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gambas-user |
|
From: Benoît M. <ga...@us...> - 2010-11-30 11:59:16
|
> Perhaps GAMBAS needs something like Python's <string> y=repr(<any> x) to > guarantee y is a string representation of x > The name of the function is CStr() - or Str$() if you need localization. Regards, -- Benoît Minisini |
|
From: Ron <ro...@cy...> - 2010-11-30 13:06:50
|
Don't want to bash, but why are CLng and CSng removed/replaced by CLong and CSingle and CStr is still there / not replaced by CString? I see some "vb logics" creeping in... same as marking text in insert and normal mode in IDE i wrote about... Back in the Gambas2 version it was so logical and cool, but I get more restless everytime the revision number goes up ;-) Regards, Ron_2nd. 2010/11/30 Benoît Minisini <ga...@us...>: >> Perhaps GAMBAS needs something like Python's <string> y=repr(<any> x) to >> guarantee y is a string representation of x >> > > The name of the function is CStr() - or Str$() if you need localization. > > 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 > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gambas-user > |
|
From: Benoît M. <ga...@us...> - 2010-11-30 13:19:26
|
> Don't want to bash, but why are CLng and CSng removed/replaced by > CLong and CSingle and CStr is still there / not replaced by CString? > They were not replaced, I just removed some abbreviations. But I admit it maye be stupid, as it just takes memory in the compiler. The interpreter does not care. > I see some "vb logics" creeping in... same as marking text in insert > and normal mode in IDE i wrote about... As for that, maybe we misunderstood each other. By pressing the INSERT key, you toggle the editor between normal mode and block/overwrite mode, like in Kate or KWrite. In block mode, insertion replaces the character under the cursor, and the selection is rectangular (a block). But maybe the problem you have is not that. I don't know, you was not very clear. > > Back in the Gambas2 version it was so logical and cool, but I get more > restless everytime the revision number goes up ;-) Gambas 3 is more logical than Gambas 2 is many places! Regards, -- Benoît Minisini |
|
From: Ron <ro...@cy...> - 2010-11-30 13:57:12
Attachments:
Screenshot-1.png
|
2010/11/30 Benoît Minisini <ga...@us...>:
>> Don't want to bash, but why are CLng and CSng removed/replaced by
>> CLong and CSingle and CStr is still there / not replaced by CString?
>>
>
> They were not replaced, I just removed some abbreviations. But I admit it maye
> be stupid, as it just takes memory in the compiler. The interpreter does not
> care.
>
Ok, I understand now I think CLng and CSng where 'aliases' of main
functions CLong and CSingle.
But CString is an 'alias' of CStr, not the main function, so the other
way around, therefor you didn't remove Cstr, is that what you are
saying?
>> I see some "vb logics" creeping in... same as marking text in insert
>> and normal mode in IDE i wrote about...
>
> As for that, maybe we misunderstood each other.
>
Yes we did apparently...
Look at the attached screenshot..
I marked -with my mouse- all the full lines of text you see in there
except the last one "Main.ControlLed("EIB", "On")
The last letters of "byte" are not back colored purple, even though I
have selected them.
It does this with all lines having comments in them
It's due to the fact that the font of the comments are different
size/type as the rest I guess, this is the default Ubuntu type theme.
> By pressing the INSERT key, you toggle the editor between normal mode and
> block/overwrite mode, like in Kate or KWrite. In block mode, insertion
> replaces the character under the cursor, and the selection is rectangular (a
> block).
>
> But maybe the problem you have is not that. I don't know, you was not very
> clear.
>
>>
>> Back in the Gambas2 version it was so logical and cool, but I get more
>> restless everytime the revision number goes up ;-)
>
> Gambas 3 is more logical than Gambas 2 is many places!
>
You are right, getting better...
Regards,
Ron_2nd.
> Regards,
>
> --
> Benoît Minisini
>
>
|
|
From: Benoît M. <ga...@us...> - 2010-11-30 14:14:44
|
> 2010/11/30 Benoît Minisini <ga...@us...>:
> >> Don't want to bash, but why are CLng and CSng removed/replaced by
> >> CLong and CSingle and CStr is still there / not replaced by CString?
> >
> > They were not replaced, I just removed some abbreviations. But I admit it
> > maye be stupid, as it just takes memory in the compiler. The interpreter
> > does not care.
>
> Ok, I understand now I think CLng and CSng where 'aliases' of main
> functions CLong and CSingle.
They were aliases.
>
> But CString is an 'alias' of CStr, not the main function, so the other
> way around, therefor you didn't remove Cstr, is that what you are
> saying?
CString and CStr are the same thing too.
>
> Yes we did apparently...
>
> Look at the attached screenshot..
> I marked -with my mouse- all the full lines of text you see in there
> except the last one "Main.ControlLed("EIB", "On")
>
> The last letters of "byte" are not back colored purple, even though I
> have selected them.
> It does this with all lines having comments in them
>
> It's due to the fact that the font of the comments are different
> size/type as the rest I guess, this is the default Ubuntu type theme.
>
No, it's a bug in Qt or in the font you use. It happens sometimes. You should
use another font!
Regards,
--
Benoît Minisini
|
|
From: Ron <ro...@cy...> - 2010-11-30 14:20:10
|
On 30-11-2010 15:07, Benoît Minisini wrote:
>> 2010/11/30 Benoît Minisini<ga...@us...>:
>>>> Don't want to bash, but why are CLng and CSng removed/replaced by
>>>> CLong and CSingle and CStr is still there / not replaced by CString?
>>> They were not replaced, I just removed some abbreviations. But I admit it
>>> maye be stupid, as it just takes memory in the compiler. The interpreter
>>> does not care.
>> Ok, I understand now I think CLng and CSng where 'aliases' of main
>> functions CLong and CSingle.
> They were aliases.
>
>> But CString is an 'alias' of CStr, not the main function, so the other
>> way around, therefor you didn't remove Cstr, is that what you are
>> saying?
> CString and CStr are the same thing too.
>
But they are threated differently, thats what I meant by vb logic...
not consistent.
>> Yes we did apparently...
>>
>> Look at the attached screenshot..
>> I marked -with my mouse- all the full lines of text you see in there
>> except the last one "Main.ControlLed("EIB", "On")
>>
>> The last letters of "byte" are not back colored purple, even though I
>> have selected them.
>> It does this with all lines having comments in them
>>
>> It's due to the fact that the font of the comments are different
>> size/type as the rest I guess, this is the default Ubuntu type theme.
>>
> No, it's a bug in Qt or in the font you use. It happens sometimes. You should
> use another font!
>
> Regards,
But it's the default font/theme for Ubuntu 10.4... I didn't change a
think about the theme.
It looks horrible too, can't you choose another one for comments in your
gambas ide project?
So it works ok always...
Regards,
Ron.
|
|
From: Ron <ro...@cy...> - 2010-12-01 13:52:31
|
Yes we did apparently...
>>>
>>> Look at the attached screenshot..
>>> I marked -with my mouse- all the full lines of text you see in there
>>> except the last one "Main.ControlLed("EIB", "On")
>>>
>>> The last letters of "byte" are not back colored purple, even though I
>>> have selected them.
>>> It does this with all lines having comments in them
>>>
>>> It's due to the fact that the font of the comments are different
>>> size/type as the rest I guess, this is the default Ubuntu type theme.
>>>
>> No, it's a bug in Qt or in the font you use. It happens sometimes.
>> You should
>> use another font!
>>
>> Regards,
>
> But it's the default font/theme for Ubuntu 10.4... I didn't change a
> think about the theme.
> It looks horrible too, can't you choose another one for comments in
> your gambas ide project?
> So it works ok always...
It looks better and works ok on Ubuntu Maverick I have just seen.
So I guess I'll upgrade my development machine too.
Ron_2nd.
|