Announcement

Collapse
No announcement yet.

Macro function skipping return value

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

    Macro function skipping return value

    This may work:

    Code:
    Function WRAPPER_LONG( ByVal nValue As Long ) As Long
        Function = nValue
    End Function
    
    Macro Function fMTEST( m )
        MacroTemp x
        Local x As Long
        x = 100 * m
    End Macro = x
    
    Macro MTEST( m ) = WRAPPER_LONG( fMTEST( m ) )
    Tested fine with:
    Code:
        Local a As Long
        a = MTEST( 200 )
        MTEST( 100 )
        MsgBox Str$( a )
    If this is confirmed i may put this in the source section.
    This has always been a hassle for me
    hellobasic

    #2
    Very dissapointing but this won't work:
    Code:
    Function WRAPPER_LONG( ByVal nValue As Long ) As Long
        Function = nValue
    End Function
    
    Macro Function fMTEST( m )
        MacroTemp x
        Local x As Long
        [B]If x = 100 Then
        End If[/B]
        x = 100 * m    
    End Macro = x
    
    Macro MTEST( m ) = WRAPPER_LONG( fMTEST( m ) )
    Called like:
    Code:
        Local a As Long
        a = MTEST( 200 )
        [B]If MTEST( 100 ) Then
        End If[/B]
        MsgBox Str$( a )
    The if/then in the macro dissallows the if and then for the macro function.
    hellobasic

    Comment


      #3
      >The if/then in the macro dissallows the if and then for the macro function.

      Technically your IF .. END IF block is illegal:
      Code:
      IF integer_expression THEN
      
        {statements}
      
      [ELSEIF integer_expression THEN
      
        {statements}]
      
      [ELSE
      
        {statements}]
      
      END IF
      The use of squiggly braces in "{statements}" means one or more statements is required in the line after the IF..THEN but before the ELSE or END IF line.

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

      Comment


        #4
        I am not convinced yet, if you swap:
        If x = 100 Then
        End If

        For:
        SELECT CASE c
        CASE 100
        END SELECT

        You'll get a nasty error.
        Also not that i use a wrapper function.

        TheMacro() is fine..
        a = TheMacro() is fine..
        But not:
        if TheMacro() then
        End If
        hellobasic

        Comment


          #5
          >TheMacro() is fine..
          >a = TheMacro() is fine..
          >But not:
          >if TheMacro() then
          >End If


          ?????


          That's documented. To use a multi-line macro in the 'function position' rather than the 'statement position' said MACRO must be a MACRO FUNCTION.

          What's not very apparent except from your observations is that a single-line macro which uses a multi-line macro counts as a multi-line macro for these purposes.

          MCM
          Last edited by Michael Mattias; 8 May 2009, 03:34 PM.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎