Code: Select all
Macro IIf (expr,truepart,falsepart)
If expr : truepart : Else : falsepart : EndIf
EndMacro
a=Random(1) : Debug a
b=Random(1) : Debug b
IIf(a=b, Debug "same", Debug "different")
Code: Select all
Macro IIf (expr,truepart,falsepart)
If expr : truepart : Else : falsepart : EndIf
EndMacro
a=Random(1) : Debug a
b=Random(1) : Debug b
IIf(a=b, Debug "same", Debug "different")
Code: Select all
Macro IIf (expr,truepart,falsepart)
If expr : truepart : Else : falsepart : EndIf
EndMacro
a=Random(1) : Debug a
b=Random(1) : Debug b
IIf(a=b, x=1, x=0)
Debug x
Code: Select all
Result$ = IIf ( (height > 190), "Tall", "Average" )
Code: Select all
Macro IIf (condition, target, trueVal, falseVal)
If condition
target = trueVal
Else
target = falseVal
EndIf
EndMacro
;-- Demo
IIf(3=4, msg$, "same", "not equal")
Debug msg$
Code: Select all
; if2.pbi
; by #Null
Procedure if2proc(condition, A.l, B.l)
If condition
ProcedureReturn A
Else
ProcedureReturn B
EndIf
EndProcedure
Macro if2(if2_condition, if2_A, if2_B)
if2proc( (0 Or (if2_condition)), if2_A, if2_B )
EndMacro
;Debug if2( 2>5, 123, 321)
Code: Select all
; strIf.pbi
; by #Null
; an ?-operator for stings. works like..
; expression ? string1 : string2
Macro StrIf( _StrIf_condition_, _StrIf_string_IF_, _StrIf_string_ELSE_="")
_StrIf_proc( 0 Or (_StrIf_condition_), _StrIf_string_IF_, _StrIf_string_ELSE_ )
EndMacro
Procedure.s _StrIf_proc( condition.l, stringIF.s, stringELSE.s)
If condition
ProcedureReturn stringIF
Else
ProcedureReturn stringELSE
EndIf
EndProcedure
; Debug "---- EXAMPLE - StrIf.pbi"
; For i=0 To 10
; r=Random(20)-10
; Debug StrIf(r>0,"+") + Str(r)
; Next
; Debug "----"
; For i=0 To 10
; r=Random(3)
; Debug StrIf(Not r,"no", Str(r)) + StrIf(r>1," seats", " seat")
; Next
; Debug "----"
Macros execute faster than procedures since the code is substituted where the calls to the macro are during compilation. This is one reason why people use them. Downside is that it can increase the size of the compiled code compared with using procedures.pdwyer wrote:I don't understand the point of a one line macro in this case,
Can't you just type what's in the macro instead of the macro? Whats the benefit?
Perhaps because I can't see what everyone else sees is why I never use macros...
Code: Select all
Macro Normalize(Red, Green, Blue)
If Red < 0
Red = 0
ElseIf Red > 255
Red = 255
EndIf
If Green < 0
Green = 0
ElseIf Green > 255
Green = 255
EndIf
If Blue < 0
Blue = 0
ElseIf Blue > 255
Blue = 255
EndIf
EndMacro