Announcement

Collapse
No announcement yet.

Forgotten () use

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

  • Forgotten () use

    While dredging through some old code I ran across the below snippet that uses () around a STRING variable
    to force the transformation to the required ASCIIZ.
    I had a remembering flash that I once used this quite extensively in early PBDLL days but it somehow faded
    into the dark recesses.
    Recently if I needed this functionality I've used BYVAL STRPTR(S1)

    Is this computer 101,PB 101 ....?

    James

    Code:
    #COMPILE EXE
    #DIM ALL
    DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hWnd AS DWORD, lpText AS ASCIIZ, lpCaption AS ASCIIZ, BYVAL dwType AS DWORD) AS LONG
    FUNCTION PBMAIN () AS LONG
        LOCAL S1      AS STRING
        LOCAL hDlg    AS LONG
        S1 = "James"
        MessageBox hDlg,(S1),"Title",IIF&(hDlg, 0, %MB_TOPMOST OR %MB_SETFOREGROUND)
    END FUNCTION

  • #2
    James,

    I still use it quite often!

    ...
    Patrice Terrier
    www.zapsolution.com
    www.objreader.com
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

    Comment


    • #3
      I always thought it was some sort of typo. (Especially after server changes)

      Never realized it was on purpose.
      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
        I did not even know that this feature existed ....
        Is this mentioned somewhere in the help file?

        Kind regards
        Last edited by Eddy Van Esch; 3 Jun 2009, 08:09 AM.
        Eddy

        Comment


        • #5
          In BASIC, using parens around a lone variable or an expression has always meant "the value of" ... kind of a shorthand "BYVAL" I guess.

          I'm pretty sure I've seen something in help re using parens to force an evaluation, I can't find it now (not that I looked all that hard... it's not on the page pointed to by "(" in the index, which only talks about operator precedence).
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            If you self-declare..

            DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hWnd AS DWORD, ByVal lpText AS String, ByVal lpCaption AS String, BYVAL dwType AS DWORD) AS LONG
            hellobasic

            Comment


            • #7
              From the help manual entry for CALL:
              http://www.powerbasic.com/support/he..._statement.htm
              Another way to force BYCOPY is to enclose a variable name in parentheses, so it will appear to the compiler as an expression, rather than just a single variable.
              Paul.

              Comment


              • #8
                I thought I'd seen use of parens documented "somewhere. "

                Shouldn't that little piece of info also be found in the index entry for "(" too?

                I'll send in a "documentation improvement suggestion. "

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

                Comment


                • #9
                  I sent this. I added the index entry idea for "()" based on this thread's title.

                  6/3/09

                  Gentlemen;

                  In PB/CC 5.0.1 and PB/Win 9.0.1 help for the CALL statement this explanation
                  appears in the sections with the "BYCOPY" caption:

                  " Another way to force BYCOPY is to enclose a variable name in parentheses,
                  so it will appear to the compiler as an expression, rather than just a
                  single variable. "

                  Yet, this same explanation does NOT appear in the help file entry linked to
                  the index entry for the left and right parens, which link only to the
                  'operator precedence' page.

                  I think you need to add a paragraph or something to show the use of parens
                  as "value forcing" in a page linked to the index entries for these symbols.

                  Or maybe better, add an index entry for the PAIR of parens "()" showing the
                  various uses of paired parens:
                  1. To establish explicit operator precedence (link to current page)
                  2. To enclose procedure parameters
                  3. To specify array subscripts
                  4. To force evaluation of a variable as an expression to take advantage of
                  the compiler's ability to make point-of-call data type conversions

                  You should also think about adding a comment about the use of parens as a
                  possibile cure for the 482 data type mismatch error in the "Errors" section
                  of the help file.

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

                  Comment


                  • #10
                    The BYCOPY () feature also exists in other languages
                    Patrice Terrier
                    www.zapsolution.com
                    www.objreader.com
                    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                    Comment


                    • #11
                      Actually, PowerBASIC recommends you avoid the use of parentheses for this purpose. The functionality was added many years ago just for compatibility with that "ancient" compiler, qb for DOS. It has persisted only to avoid unnecessary problems moving from version to version with PowerBASIC. We removed documentation in order to foster adoption of other alternatives, specifically the BYCOPY override option. This provides the identical functionality, yet makes the purpose obvious when you visit the code later.

                      Best regards,

                      Bob Zale
                      PowerBASIC Inc.

                      Comment


                      • #12
                        Actually, PowerBASIC recommends you avoid the use of parentheses for this purpose
                        I don't suppose a futher documentation improvement suggestion to cancel my suggestion from yesterday and replace it with a suggestion to REMOVE the "helpful BYCOPY hint" in the doc for CALL is necessary.

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

                        Comment

                        Working...
                        X