View Full Version : "macro" convert how into thinbasic?
largo_winch
18-01-2012, 21:11
How I can convert a "macro" on the fly to thinbasic?
' Empty GUI script created on 01-18-2012 20:04:16 by (ThinAIR)
Uses "console"
MACRO myMoney(d,l) = "EURO" + RSet$(Format$(d, "#,.00"), l - 1)
Function TBMain () As Long
Local a As String
a = myMoney(2345.67, 13)
MsgBox 0, a 'result should be: "euro 2,345.67"
End Function
bye, largo
Petr Schreiber
18-01-2012, 21:22
Hi largo_Winch,
the rules for conversion of PB MACRO functionality are simple:
Type 1: MACRO serves to create alias
Example:
MACRO myFloat = SINGLE
Converted - via ALIAS:
ALIAS SINGLE AS myFloat
Type 2: MACRO serves as kind of functionality shortcut
Example (yours):
MACRO myMoney(d,l) = "EURO" + RSet$(Format$(d, "#,.00"), l - 1)
Converted - via FUNCTION:
function myMoney( d as double, l as long ) as string
return "EURO" + RSet$(Format$(d, "#,.00"), l - 1)
end function
Petr
largo_winch
18-01-2012, 21:49
thank you petr for fast reply!
one more question: do you think this macro looks like more for a "function" or than "alias" ?
MACRO myLONYB (byt) = byt Mod 16
Alias byt Mod 16 as myLonyB(byt)
(meaning for byt = byte.)
"mod" command isn't used here correct, I know, it's just the question "alias" or "function" I am interested in ;)
'n = MOD(numeric_expression_1, numeric_expression_2)
I suggest that's look like more than function :oops:
Function myLonyB(byt As Byte)
Return Mod(byt,16)
End Function
bye, largo
Petr Schreiber
19-01-2012, 22:01
Hi,
I think your function version is exactly how I would do it (maybe I would just add AS BYTE).
The alias is good for 1:1 relationship, that is renaming one thing to another. Once it gets more complex, the function form is the right emulation approach.
Petr