Results 1 to 4 of 4

Thread: "macro" convert how into thinbasic?

  1. #1

    "macro" convert how into thinbasic?

    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

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,150
    Rep Power
    736
    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
    Last edited by Petr Schreiber; 18-01-2012 at 21:24.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    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

    Function myLonyB(byt As Byte)
        Return Mod(byt,16)
    End Function
    
    bye, largo
    Last edited by largo_winch; 18-01-2012 at 21:59.

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,150
    Rep Power
    736
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. googling for "thinbasic" strange links
    By largo_winch in forum General
    Replies: 1
    Last Post: 08-09-2011, 16:13
  2. thinBasic mentioned in "Webster's Quotations, Facts and Phrases"
    By Petr Schreiber in forum thinBasic where ...
    Replies: 0
    Last Post: 17-08-2010, 11:18
  3. Uses "File", "Crypto" ... ???
    By marcuslee in forum thinBasic General
    Replies: 3
    Last Post: 01-12-2009, 19:38
  4. thinBasic listed in "automation" page
    By ErosOlmi in forum thinBasic where ...
    Replies: 0
    Last Post: 13-02-2009, 12:23

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •