# PureBasic Forum

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

 All times are UTC + 1 hour

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Expansion of Macros with ParametersPosted: Tue Mar 13, 2012 11:03 am
 Enthusiast

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

 Post subject: Re: Expansion of Macros with ParametersPosted: Tue Mar 13, 2012 11:10 am
 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

 Post subject: Re: Expansion of Macros with ParametersPosted: Tue Mar 13, 2012 1:14 pm

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

 Post subject: Re: Expansion of Macros with ParametersPosted: Tue Mar 13, 2012 3:22 pm
 Enthusiast

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite