Announcement

Collapse
No announcement yet.

Why are expressions not always allowed?

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

  • Why are expressions not always allowed?

    I've noticed before, that some PowerBASIC statements allow expressions, but some require variables.

    For example, the RegRepl requires a variable/value for iEnd.

    Code:
    RegRepl "[ ]+" In temp$ With " " At 1 To iEnd, tmp$
    This fails:
    Code:
    RegRepl "[ ]+" In temp$ With " " At 1 To Len(temp$), tmp$
    Is there a general reason why PowerBASIC statements differ on this requirement?

  • #2
    >Is there a general reason why PowerBASIC statements differ on this requirement?

    The general reason is, you misunderstood the doc. The variables immediately following the "TO" are variables to be filled when the statement is executed. You can't fill an expression.

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

    Comment


    • #3
      Thanks MCM, but you misunderstood my question.

      I know the DOC says variables, and will NOT allow expressions.

      But various other statements in PowerBASIC do allow expressions.

      Why is that? Because PowerBASIC Inc. says so may be the answer, but I thought there might be some logic to it.

      Comment


      • #4
        >But various other statements in PowerBASIC do allow expressions.

        Not for variables which are filled by a statement. It's impossible.

        It's like saying
        Code:
          (Z+4) =  INSTR ("quick", "The quick brown fox")
        What, it's supposed to solve for Z?
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          RegRepl "[ ]+" In temp$ With " " At 1 To iEnd, tmp$
          It looks like Gary is thinking that AT and TO are to indicate the starting and ending positions. Not so. You should read it as:

          RegRepl "[ ]+" In temp$ With " " At 1 To iPos, tmp$
          where iPos is a variable that will receive the character position immediately following the matched text in tmp$, or zero, if no matching expression is found.

          You can only indicate an starting position, not an ending position.
          Forum: http://www.jose.it-berater.org/smfforum/index.php

          Comment


          • #6
            Jose,

            Yep, that is exactly what I did. Thinking it was a value I was to supply, I didn't see the reason to disallow and expression.

            Even when I read it the first time, I thought it peculiar that the TO would be followed by an input, rather than most other statements where TO precedes a variable to receive a value.

            I should have paid attention to that nagging thought.

            Thanks for the help,
            Gary

            Comment


            • #7
              You're not alone with that error! I did it with:
              Code:
              GRAPHIC TEXT SIZE txt$ TO nWidth!, nHeight!
              Because I wanted to set the text size to a width and height it sure looked like I could do it with it even though that isn't what it says.
              Rod
              In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

              Comment


              • #8
                I thought I had seen the "no expression" allowed in other statements, but din't make any notes. Now I'll be alert for when it happens - to see if it was simply my mis-understanding

                Darn Rodney, late night for us. Thanks for the "you're not alone" comment.

                Comment


                • #9
                  AFAIK, any variables following a "TO" in any intrinsic statement are "to be filled" on successful execution... including
                  Code:
                     CALL functionname (params )  [COLOR="Red"][b]TO  resultvar [/b][/COLOR]
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    AFAIK, any variables following a "TO" in any intrinsic statement are "to be filled" on successful execution..
                    As far as I know too, but when you want to set a
                    graphic's text size to mywidth, myheight
                    GRAPHIC TEXT SIZE txt$ TO width%, height%

                    sure looks like it should work, especially in the wee small hours of the morning.
                    Rod
                    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                    Comment


                    • #11
                      > sure looks like it should work, especially in the wee small hours of the morning.

                      Reminds me of the old Mickey Gilley song...

                      "Oh the girls all get prettier at closin' time,
                      They all begin to look like movie stars,
                      ..."
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        > AFAIK, any variables following a "TO" in any intrinsic statement are "to be filled" on successful execution

                        Hmm, I guess not....... ARRAY SORT's syntax uses 'TO' to precede a supplied parameter.
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          You beat me to it by less than a minute.
                          "Not my circus, not my monkeys."

                          Comment


                          • #14
                            By sheer coincidence I needed ARRAY SORT() for something yesterday. As soon as I typed "FROM iStart TO " this thread popped into my mind.

                            But as long as it's on the table, it's curious how PB did not use the "FROM x FOR y " format used in other commands which accept a range.
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              The ARRAY...FROM...TO syntax predates the use of TO (result) by quite some time, IIRC. Bob is good, but he doesn't have the ability to foresee all of the possible uses of a word like TO.

                              -- Eric
                              "Not my circus, not my monkeys."

                              Comment


                              • #16
                                One of the first things I learned when I started programming was the importance of the little words in the documentation. Words like "if", "to", "for", "a", "the", "any", etc. and now that a lot of them have become part of the actual programming(for always was) language, being a little more attentive to them is time saving.
                                Rod
                                In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                                Comment


                                • #17
                                  >was the importance of the little words in the documentation ...

                                  ...and not just in the documentation!

                                  Four-letter words are short words, and several are used frequently during the development process.


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

                                  Comment


                                  • #18
                                    Four-letter words are short words, and several are used frequently during the development process.
                                    You can hear me that far away??
                                    Rod
                                    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                                    Comment

                                    Working...
                                    X