It is currently Wed Jun 19, 2013 8:14 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Expansion of Macros with Parameters
PostPosted: Tue Mar 13, 2012 11:03 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 410
Hi guys. A simple question: how do such macros insert themselves into the actual code:
Code:
Macro doStuff(which)
  If which = 1
    ;do 1st routine
  ElseIf which = 2
    ;do 2nd routine
  ElseIf which = 3
    ;do 3rd routine
  EndIf
EndMacro

doStuff(3)   ;calling 3rd routine

doStuff(2)   ;calling 2nd routine
Is it:
Code:
If which = 1
  ;do 1st routine
ElseIf which = 2
  ;do 2nd routine
ElseIf which = 3
  ;do 3rd routine
EndIf

If which = 1
  ;do 1st routine
ElseIf which = 2
  ;do 2nd routine
ElseIf which = 3
  ;do 3rd routine
EndIf
or:
Code:
;do 3rd routine

;do 2nd routine
Thanks.

_________________
Texas Instruments 99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
 
 Post subject: Re: Expansion of Macros with Parameters
PostPosted: Tue Mar 13, 2012 11:10 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Jul 09, 2011 7:57 am
Posts: 276
doStuff(3) equal to

Quote:
If 3 = 1
;do 1st routine
ElseIf 3 = 2
;do 2nd routine
ElseIf 3 = 3
;do 3rd routine
EndIf

_________________
http://www.mediafire.com/pbstuff


Top
 Profile  
 
 Post subject: Re: Expansion of Macros with Parameters
PostPosted: Tue Mar 13, 2012 1:14 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 2269
Location: Italy
If you want to check how a macro is expanded, just put some garbage at the end of the macro.

Code:
Macro doStuff(which)
  If which = 1
    ;do 1st routine
  ElseIf which = 2
    ;do 2nd routine
  ElseIf which = 3
    ;do 3rd routine
  EndIf
  *
EndMacro



Then try to compile. In the macro error window you will see:

Code:
If 3 = 1
ElseIf 3 = 2
ElseIf 3 = 3
EndIf
*   ;calling 3rd routine routine



Just remove the "*" to see how the macro has been expanded.

_________________
[ Home ] [ My PC ] [ New to PB ? ]


Top
 Profile  
 
 Post subject: Re: Expansion of Macros with Parameters
PostPosted: Tue Mar 13, 2012 3:22 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 410
xorc1zt wrote:
doStuff(3) equal to
Quote:
If 3 = 1
;do 1st routine
ElseIf 3 = 2
;do 2nd routine
ElseIf 3 = 3
;do 3rd routine
EndIf
Thanks for the clarification, xorc1zt.

And luis, thank you for pointing out the Macro Error window; you guys are right, and that confirms it.

_________________
Texas Instruments 99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye