Announcement

Collapse
No announcement yet.

Prefix End Prefix Statements

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

  • Prefix End Prefix Statements

    Please add your comments and suggestions as a Reply to this thread.





    PB/WIN - PREFIX/END PREFIX statements

    Purpose
    Executes a series of statements, each of which utilizes pre-defined source code.
    Syntax
    PREFIX "source code"
    [additional statements]
    END PREFIX
    Remarks
    PREFIX/END PREFIX statements enclose a set of statements, each of which has the same specified "source code" prepended. The "source code" (in languages which support it) is usually required to be the name of an object variable. However, in PowerBASIC, this definition has been expanded greatly to allow virtually any code to be used. This reduces repetitive typing and reduces the risk of typing errors. For example:
    PREFIX/END PREFIX
    Compiles as:
    PREFIX "MyObject."
    Init(xx)
    Sleep(2)
    END PREFIX
    MyObject.Init(xx)
    MyObject.Sleep(2)
    PREFIX "MyStruc."
    Height = 220
    Width = 345
    Color = %Blue
    END PREFIX
    MyStruc.Height = 220
    MyStruc.Width = 345
    MyStruc.Color = %Blue
    PREFIX "ASM"
    Mov Eax, Ebx
    Mov Ecx, &H14
    IMul Eax, Esi
    END PREFIX
    ASM Mov Eax, Ebx
    ASM Mov Ecx, &H14
    ASM IMul Eax, Esi
    If the "source code" prefix refers to an object variable or a UDT structure variable, be sure it ends with a period (.) to reference members of that item. Otherwise, be sure it contains whole words. Just as with macros and line continuations, you cannot put half a word on one line, and half a word on another. For example, the following code is illegal and will generate an exception:

    Code:
    PREFIX "PRI"
      NT #1, "Hello World"
    END PREFIX
    PREFIX/END PREFIX structures may not be nested.
    See Also
    Last edited by Gary Beene; 28 Oct 2014, 10:08 PM.

  • #2
    Code:
    Prefix "Data "
        "AL", 3444354, 3894025, 4040587, 0, 0, 0.0, 0.0, 0.0
        "AK", 302583, 401851, 550043, 0, 0, 0.0, 0.0, 0.0
        "AZ", 1775399, 2716546, 3665228, 0, 0, 0.0, 0.0, 0.0
    End Prefix
    is not allowed.
    You'll get an
    'Error 641 in E:\PROJEKTE\DDE\PB\ATOMS\SERVER\DDESERVER.INC(91:012): DATA may not be used with PREFIX

    so the Errorlist should also be actualized
    _______________________
    mit freundlichen Grüßen / Sincerely
    Peter
    The two basic principles of Windows System Administration:
    For minor problems, reboot. For major problems, reinstall
    !

    Comment


    • #3
      Interesting, "error 641" not in Help.
      Dale

      Comment


      • #4
        Originally posted by Dale Yarker View Post
        Interesting, "error 641" not in Help.
        Yep, the "Additional Changes" in Hep ony lists new errors up to 640. Maybe that error was added in a minor release. as a result of feedback.

        Comment


        • #5
          Hi Peter,

          It is probably the case the a DATA statement is a lot more complex under the hood than a simpler code statement and it has to do with the order that code is evaluated by the multipass compiler. I imagine that a DATA statement is evaluated and turned directly into binary before the PREFIX pair is done so it will produce an error when attempted.
          hutch at movsd dot com
          The MASM Forum

          www.masm32.com

          Comment


          • #6
            Interesting, while the

            Code:
            PREFIX "PRI"
                 NT #1, "Hello World"
            END PREFIX
            doesn't work, this does:
            '
            Code:
             PREFIX "lngMyLongArrayName("
                   1) = 42
                   2) = 87
                   3) = 99
                   4) = 120
             END PREFIX
             ? STR$(lngMyLongArrayName(4))
            '

            Comment


            • #7
              Interesting is right!
              This doesn't work.
              Code:
                LOCAL lngMyLongArrayName() AS LONG
                DIM lngMyLongArrayName(11 TO 14)
                PREFIX "lngMyLongArrayName(1"
                     1) = 42
                     2) = 87
                     3) = 99
                     4) = 120
               END PREFIX
               ? STR$(lngMyLongArrayName(14))
              Error 411 in C:\PBWin10\Canasta\canasta1.bas(245:008): "," expected
              Line 245: 1) = 42
              Expanded(22): lngMyLongArrayName(1 1) = 42
              Half a word=half a term
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment


              • #8
                Does ordinary text stuff correctly.
                Code:
                ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                
                FUNCTION PBmain as LONG
                
                    PREFIX "StdOut "
                      "The time has come, the Walrus said,"
                      "      To talk of many things:"
                      "Of shoes and ships and sealing-wax"
                      "      Of cabbages and kings"
                      "And why the sea is boiling hot"
                      "      And whether pigs have wings."
                    END PREFIX
                
                    waitkey$
                
                End FUNCTION
                
                ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                I think it being test is the action and avoids the first pass actions.

                Vaguely I remember Bob in the beta testing ensured that a space occurred after the PREFIX text. It works without the space after the "StdOut".
                hutch at movsd dot com
                The MASM Forum

                www.masm32.com

                Comment


                • #9
                  This works OK as well.
                  Code:
                      Open "test.txt" for Output as #1
                  
                      PREFIX "Print #1, "
                        "The time has come, the Walrus said,"
                        "      To talk of many things:"
                        "Of shoes and ships and sealing-wax"
                        "      Of cabbages and kings"
                        "And why the sea is boiling hot"
                        "      And whether pigs have wings."
                      END PREFIX
                  
                      Close #1
                  hutch at movsd dot com
                  The MASM Forum

                  www.masm32.com

                  Comment


                  • #10
                    Wow Peter, I thought by now we had visited all of the dark, lonely corners in PB, but you found a new one.
                    "Not my circus, not my monkeys."

                    Comment


                    • #11
                      Perhaps, we shouldn't be using PREFIX statements at all !!!

                      Comment


                      • #12
                        Why? Don't use with DATA, split command words or numbers across lines. Not splitting words is covered in help.
                        Dale

                        Comment


                        • #13
                          Originally posted by Anne Wilson View Post
                          Perhaps, we shouldn't be using PREFIX statements at all !!!
                          Why not?

                          Comment


                          • #14
                            I can follow Hutch's thought. We cannot see what the compiler does internally. I also assumed in the beginning that PB first includes, expands and prepares all text and only then goes into action and compiles. However, it looks like evaluations are already being done in the process when I look at the results here. I find PREFIX quite handy. Instead of writing
                            Code:
                            ' // Set the headers
                              pGrid.TextMatrix(0, 1) = "Customer ID"
                              pGrid.TextMatrix(0, 2) = "Company Name"
                              pGrid.TextMatrix(0, 3) = "Contact Name"
                              pGrid.TextMatrix(0, 4) = "Contact Title"
                              pGrid.TextMatrix(0, 5) = "Address"
                              pGrid.TextMatrix(0, 6) = "City"
                              pGrid.TextMatrix(0, 7) = "Region"
                              pGrid.TextMatrix(0, 8) = "Postal Code"
                              pGrid.TextMatrix(0, 9) = "Country"
                              pGrid.TextMatrix(0, 10) = "Phone"
                              pGrid.TextMatrix(0, 11) = "Fax"
                            we can write
                            Code:
                            ' // Set the headers ' // Überschriften eintragen
                              Prefix "pGrid.TextMatrix(0, "
                                1) = "Kunden ID" 'Customer ID"
                                2) = "Firmename" 'Company Name"
                                3) = "Kontaktname" 'Contact Name"
                                4) = "Kontakt Titel" 'Contact Title"
                                5) = "Adresse" 'Address"
                                6) = "Stadt" 'City"
                                7) = "Region"
                                8) = "Postleitzahl" 'Postal Code"
                                9) = "Land" 'Country"
                                10) = "Telefon" 'Phone"
                                11) = "Fax"
                              End Prefix
                            which I think is much better to read.

                            I think, Rodney captured it: Avoiding breaks of Words,Terms or Statements.
                            ----------

                            Regarding the error list, there I can add that I have already encountered error 410 as well:
                            Error 410: "." expected
                            - The command syntax requires a dot (.)
                            _______________________
                            mit freundlichen Grüßen / Sincerely
                            Peter
                            The two basic principles of Windows System Administration:
                            For minor problems, reboot. For major problems, reinstall
                            !

                            Comment


                            • #15
                              I'm only missing this:
                              Code:
                              PREFIX "REM "
                                 Multiline comment
                                 goes here
                              END PREFIX
                              Interestingly, the IDE is coloring this properly, but not compiling for some reason.. (IDE Version 10.04.0108)

                              Click image for larger version

Name:	1.jpg
Views:	44
Size:	53.6 KB
ID:	805151

                              Comment


                              • #16
                                What error was reported? Missing MAIN/PBMAIN function?
                                Or, Declaration must precede statements?
                                Dale

                                Comment


                                • #17
                                  Maybe try the #UTILITY metastatement.

                                  or

                                  #IF 0
                                  whatever you want here
                                  #ENDIF
                                  Last edited by Rodney Hicks; 23 Feb 2021, 03:52 PM. Reason: add #IF / #ENDIF configuration
                                  Rod
                                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                  Comment


                                  • #18
                                    This:
                                    Code:
                                    #IF 0
                                    PREFIX "rem "
                                    This is a
                                    multiline comment
                                    END PREFIX
                                    #ENDIF
                                    colours the comments

                                    This also works, but capitalises/colours the text IAW IDE rules
                                    Code:
                                    #IF 0
                                    This is a
                                    multiline comment
                                    #ENDIF

                                    Comment


                                    • #19
                                      Error 484: Requires Procedure (Function/Method...)

                                      I'm using #IF 0 ... #ENDIF, but IDE doesn't recognize this pair as block comment and it looks ugly... Still sticking with short REM replacement

                                      Comment


                                      • #20
                                        Originally posted by Dale Yarker View Post
                                        What error was reported? Missing MAIN/PBMAIN function?
                                        Or, Declaration must precede statements?
                                        If outside of a procedure:
                                        Error 484 Requires Procedure (Function Method)

                                        If inside a procedure:
                                        Error 516 DefType, Type id (?%&!#$), or AS... required: REM

                                        Comment

                                        Working...
                                        X