Announcement

Collapse
No announcement yet.

ISFILE() Function and %TRUE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ISFILE() Function and %TRUE

    Hello,

    I found the new function ISFILE() very useful.

    At first I used it the wrong way like that :

    Code:
    IF ISFILE(lFilename) = %TRUE THEN ...
    This code could not work properly; I understood later that I was wrong because from the documentation, the value true (-1) is returned when the file is found and the value for the numeric equates %TRUE is 1; so here is my question :

    Why the true value (-1) returned by the ISFILE function is different from the numeric equates %TRUE (1) defined in Win32API.inc ? or why the value for numeric equates %TRUE is 1 and not -1 in Win32API.inc ?

    Thanks
    Jean-Pierre
    Jean-Pierre LEROY

  • #2
    %TRUE in Windows-speak is "non-zero" and may be defined as any non-zero value; that is your code - if properly written - should work if you define:
    Code:
    %TRUE = 8752019
    The PB "ISTRUE" function could be defined with a MACRO:
    Code:
    MACRO ISTRUE (X) =  IIF& (X <> 0, -1&, 0)
    You ISFILE code would have worked had you coded..
    Code:
      IF ISTRUE ISFILE(fileSpec) THEN 
      ...
    or even
    Code:
     IF ISFILE (filespec) THEN
    .. either of which would be a better way to code it.

    You think this is confusing, throw in a few NOTs and then tell us with a straight face you don't appreciate ISTRUE's sibling, ISFALSE.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Or short and sweet
      %False = 0
      %True = (well it depends on the function asked, but truthfully would be ANYYYYYTHING that is not zero) and it is up to the question that is asked if so called "TRUE" or "False"
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        This works for me:
        %false = 0
        %true = not %false

        By MM
        ...throw in a few NOTs ...
        There are no atheists in a fox hole or the morning of a math test.
        If my flag offends you, I'll help you pack.

        Comment


        • #5
          Michael, Cliff and Mel,

          Thank you for your answers.

          I appreciate your support.
          Jean-Pierre LEROY

          Comment


          • #6
            to clearly understand, have a look in the Helpfile "ISFALSE and ISTRUE operators" ... or see this

            ? Isfile() -> 0 or -1
            ? NOT Isfile() -> -1 or 0

            inside (Power)Basic it is no Problem to ask with 'NOT',
            but with the Windows API ...

            ? %true -> 1 'OK
            ? not %true -> -2 (this should be 0 )
            ? %false -> 0 'OK
            ? not %false -> -1 'OK
            Regards,
            Hubert

            ------------------------------------
            http://familie-brandel.de/index_e.html

            Comment


            • #7
              It's pretty simple, all you need to do is to check whether the value is FALSE or not, if it's not FALSE then it's TRUE (any arbituary value).

              Code:
               IF (val <> %FALSE) THEN
                 ' Value is TRUE
              END IF
               
              IF (val = %FALSE) THEN
                 ' Value is FALSE
              END IF
              FALSE is ALWAYS zero with PowerBASIC and the Win32 API. No exceptions.
              kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

              Comment


              • #8
                As far as I am concerned, you should NEVER test a variable for equality with TRUE or FALSE; you should always use ISTRUE and ISFALSE.

                Maybe with FALSE it's OK, but certainly not with TRUE.

                MCM
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  My previous workaround for something like this used to be:
                  Code:
                  IF NOT (variable = 0) THEN ...
                  Furcadia, an interesting online MMORPG in which you can create and program your own content.

                  Comment


                  • #10
                    FALSE is ALWAYS zero with PowerBASIC and the Win32 API. No exceptions
                    TRUE and FALSE are logical concepts, not integer values.

                    However, since few BASICs support a LOGICAL or BOOLEAN data type, as far as I can recall TRUE and FALSE have always been implemented as either an on/off BIT or a non-zero/zero integer.

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Just use the boolean function value like this:

                      IF ISFILE(lFilename) THEN

                      OR

                      IF NOT ISFILE(lFilename) THEN

                      then no need to make further comparison...
                      Patrice Terrier
                      www.zapsolution.com
                      www.objreader.com
                      Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                      Comment


                      • #12
                        TRUE and FALSE are logical concepts, not integer values.
                        Not in PB/WIN they aren't. In PB, values are compared, not concepts.

                        I've made my point, no further discussion required.
                        kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                        Comment

                        Working...
                        X