Announcement

Collapse
No announcement yet.

Need some simple examples of MACRO

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

  • Need some simple examples of MACRO

    Hi All

    I have seen the usage of macros being used, I w'd like to have some example codes of Macro
    their mechanisms do look cool. All help appreciated

  • #2
    All sorts of example in here. The second version is in post #23 of that thread.
    Rod
    "To every unsung hero in the universe
    To those who roam the skies and those who roam the earth
    To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

    Comment


    • #3
      Awesome examples , Big Thank you to you Rodney

      Comment


      • #4
        I use macros all the time.

        I first used (non-PB) macros in 1967!!!! In those far off days there were limits on how many macro lines in total you could have - and I was always on the limit. When I discovered PB macros with no (practical) limits and a depth of up to three, I was in programming heaven.
        [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
        Kerry Farmer

        Comment


        • #5
          I find macros useful for defining "custom" data types. For example, MACRO VAR32 = STRING * 32 which makes naming TYPE elements and function arguments easier (e.g. AES key and HMAC values). I also have some functions, such as a 32-bit time library, that will work correctly with LONG or DWORD values but not both. So I use MACRO TIME32 = DWORD which prevents me from inadvertently mixing things up.

          Comment


          • #6
            Thanks Kerry ,,,,,,,, macros already in place before 1967! wow it is way older than myself

            Thanks Jerry , yes we would definitely need custom data definition via Macros

            Comment


            • #7
              Here's another interesting use for a macro that I came across some time ago. It provides a way to test an expression and exit a procedurle (FUNCTION, SUB, METHOD, whatever) with an error code if the expression is true. I find it useful for testing input arguments. It could even be expanded to display/log error information - maybe passing a string error value to the macro. Since the macro code lives within the "parent" procedure, it knows some stuff about that procedure (e.g. procedure name, thread ID).

              Code:
              MACRO TestExpression(expression, errVal, procType)
                IF expression THEN
                  '---> Maybe some logging could happen here?
                  procType = errVal
                  EXIT procType
                END IF
              END MACRO
              
              
              FUNCTION MyFunction( _
                  BYVAL lpData  AS LONG, _  ' Ptr to some data (NULL not good)
                  BYVAL dLen    AS LONG, _  ' Lenth of data (0 also not good)
                  BYVAL sName   AS STRING _ ' Empty strings also bad
                  ) AS LONG
              
                '-- Test argument values. Failures will cause express exit from procedure.
                TestExpression(lpData = 0, 1, FUNCTION)
                TestExpression(dLen = 0, 2, FUNCTION)
                TestExpression(LEN(TRIM$(sName)) = 0, 3, FUNCTION)
              
                '-- Arguments look OK (for now) so continue.
                'code code code
              
              END FUNCTION

              Comment


              • #8
                Originally posted by Tim Lakinir View Post
                Thanks Kerry ,,,,,,,, macros already in place before 1967! wow it is way older than myself

                Thanks Jerry , yes we would definitely need custom data definition via Macros
                Quit a bit before 1967.

                From the Wikipedia article on macros:

                "In the mid-1950s, when assembly language programming was commonly used to write programs for digital computers, the use of macro instructions was initiated...

                Comment


                • #9
                  Originally posted by Stuart McLachlan View Post

                  Quit a bit before 1967.

                  From the Wikipedia article on macros:

                  "In the mid-1950s, when assembly language programming was commonly used to write programs for digital computers, the use of macro instructions was initiated...
                  Somewhat before my time!!!!
                  [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                  Kerry Farmer

                  Comment


                  • #10
                    Thanks Jerry that is a very good MACRO as it simplify exit function or exit sub and there is less clutter in the code

                    Comment

                    Working...
                    X