Format> Function

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Format> Function

Post by JRL » Mon Mar 16, 2015 9:56 pm

A few questions and comments about the Format> function. Using Format>%x does a great job of converting decimal to hexadecimal. I expected that perhaps Format>%-x would convert hexadecimal to decimal but it does not. We will need to continue using VBEval>CLng for that purpose.

I often have to place leading zeros on a number so I am very happy with using for example Format>%.6d,43,result which sets result to 000043. However I did find that there is a limit of 16 for the precision parameter and if the decimal number being modified is too large the result is a number that appears to be gibberish. (see the example below.)

Hoping that the Format> pointer parameter might create a pointer to a memory location so we can use an extended set of Microsoft APIs that for example, require pointers to structures. But I could not find any way to format the Format>%p that did not give me an error.

Anyone have any experiences or information they'd like to share?


Code: Select all

//Format: convert decimal to hexadecimal
Format>%x,324234,result

//VBScript: convert hexadecimal to decimal
VBEval>CLng("&h" & "%result%"),dec

//VBScript: convert decimal to hexadecimal
VBEval>hex(324234),result2


//Format: pad 16 zeros to the left of a 4 place integer
//returns a left padded 16 place integer.
Let>data=1234
Format>%.16d,data,result
MDL>result

//Format: pad 17 or more zeros to the left of a 4 place integer
//returns the original number
Let>data=1234
Format>%.17d,data,result
MDL>result

//Format: pad 16 zeros to the left of an 18 place integer
//returns ???
Let>data=123456789123456789
Format>%.16d,data,result
MDL>result 

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Format> Function

Post by Marcus Tettmar » Mon Mar 23, 2015 2:46 pm

Hi,

16 is indeed the limit for the precision at this time.

Format is just designed to allow you to DISPLAY values in a nice human readable form. So the pointer thing is to display a pointer value as a string. It won't give you anything low level or esoteric like an actual memory address. If you HAD a pointer you could use it to display it nicely. However, Macro Scheduler doesn't support pointer types in the first place and everything is already string-like so this is redundant really. It's there in the docs because the Format function is inherited from the Delphi Format function which does this. Realistically I think it's meaningless in respect to Macro Scheduler as you aren't going to end up with a pointer you can convert anyway. I probably should have removed it from the docs, but had copied it from the delphi docs.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Format> Function

Post by JRL » Mon Mar 23, 2015 3:05 pm

Marcus,
Thanks for the info and clarification.

The Format> function is a nice addition to Macro Scheduler capabilities. I've incorporated it into a couple of scripts padding left zeros because its more concise than using the VBScript method. I can never remember the VBScript method so I always have to search for it. The concise Format> syntax is way easier to remember.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts