Announcement

Collapse
No announcement yet.

Equates-Where to define

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

  • Equates-Where to define


    Current code and functions well:

    %Blue = 1
    PRINT "Hello"
    PRINT %Blue
    END

    -----------------------------------------------

    I want something like the following, however,
    PB for DOS 3.5 does not like it.

    Error 460: You used a named constant in your
    program without defining it. Define the
    named constant or use a literal constant
    in the statement.

    GOSUB Junk:
    PRINT "Hello gang"
    PRINT %Blue <---- error
    END

    Junk:
    %Blue = 1
    RETURN

    -----------------------------------------------

    I know there is a nice way to get what I want.
    Point me in the right direction.

    Thanks for the advice, Jack


    ------------------

  • #2
    An equate must <U>physically</U> precede in the source code or #INCLUDE'd files its use in a statement or expression.

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

    Comment


    • #3
      Jack, equates have to be declared outside of Subs and Functions. Also, %BLUE
      is a numeric value. You have to convert it to string form to print it:
      Code:
      #COMPILE EXE
      
      %BLUE = 1
      
      FUNCTION PrintBlue
          Local a$
            a$ = STR$(%BLUE)
            PRINT a$
             END FUNCTION


      ------------------
      Mark Pruitt
      [email protected]
      sigpicMark Pruitt
      [email protected]

      http://ezreregister.com
      Manage 3rd party BlackBerry software registration codes.

      It's not the only way to do it...just the EZ way!

      Comment


      • #4
        Mark --

        > Also, %BLUE is a numeric value. You have to
        > convert it to string form to print it

        Sorry, that's not correct. PRINT %BLUE is fine.

        Jack --

        I typically create a separate $INCLUDE file for all of my generic equates like %BLUE, and then $INCLUDE the file in my projects near the very top of the source code. That way all of my equates will be defined before the compiler starts looking at the rest of my code. Alternatively you can place equates themselves at the "physical" top of your main source code file. As long as they are defined before they are used, PB won't complain.

        -- Eric

        ------------------
        Perfect Sync Development Tools
        Perfect Sync Web Site
        Contact Us: mailto:[email protected][email protected]</A>

        [This message has been edited by Eric Pearson (edited August 09, 2003).]
        "Not my circus, not my monkeys."

        Comment


        • #5
          I knew you folks would have a nice solution, works like a charm.
          Thanks, Jack


          ------------------

          Comment


          • #6
            Eric, I didn't know you could print equates without converting them! You can
            learn a lot and get smarter hanging out around these forums.

            I just tried the following in PBCC, and to my amazement both values printed!

            Code:
            #COMPILE EXE
            
            %BLUE = 1
            
            FUNCTION PBMAIN () AS LONG
            
              LOCAL n&
                n& = 2
                  PRINT %BLUE
                  PRINT n&
                    WAITKEY$
            END FUNCTION
            It would appear I have some more meditating to do over the STR$ and VAL statements.



            ------------------
            Mark Pruitt
            [email protected]
            sigpicMark Pruitt
            [email protected]

            http://ezreregister.com
            Manage 3rd party BlackBerry software registration codes.

            It's not the only way to do it...just the EZ way!

            Comment

            Working...
            X