[Gambas-user] Removing / Modifying IsXXXX() functions in Gambas3

Benoît Minisini gambas at ...1...
Mon Nov 29 18:38:25 CET 2010


> > 
> > 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




More information about the User mailing list