Simple Unit Converter.

Discuss and share scripts and script files...
Post Reply
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Simple Unit Converter.

Post by SkyFrontier »

This is a very basic unit converter.
ToDo: allow multiple formats as input (no skills for this currently - if you're up to the task, feel free to add your contribution!).

Code: Select all

//works on XYplorer v +9.70.0007
   end (<xyver> < "9.70.0007"), "Sorry - this script requires XYplorer version 9.70.0007 or higher.<crlf>Click 'Ok' to exit.";
   msg "This will convert any size (raw = no decimals) in the unit you indicate in the next screen. <crlf>Allowed:<crlf><crlf>FLEX = [Default] Flexible (best unit is auto-selected).<crlf>FLEXR = FLEX, but rounded up.<crlf>KB, MB, GB, TB, or PB = usual bytes unit.<crlf>KBR = KB, but rounded up.<crlf>BB = Bytes (with unit)<crlf>B = Bytes (no unit)<crlf>RAW = Raw number (no unit, no thousand separators).", 1, ;
   input $v, "Please enter the value to be converted (raw = no decimals):", "1024";
   input $u, "Please enter the unit you want (FLEX/FLEXR/KB, MB, GB, TB, or PB/KBR/BB/B/RAW):", "FLEX";
   $a = formatbytes($v, "$u", -1);
   echo "Original $v equals to $a.";
   copytext $a;
   status "Value on clipboard, too. Have a g'day!";
EDIT: Fixed misspelling.
EDIT: Compatibility check added.
Last edited by SkyFrontier on 12 Nov 2010 11:37, edited 2 times in total.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Simple Unit Converter.

Post by SkyFrontier »

...and the ninja style 8) version of this (=complex unit conversions!):

Code: Select all

//works on XYplorer v +9.70.0007
   end (<xyver> < "9.70.0007"), "Sorry - this script requires XYplorer version 9.70.0007 or higher.<crlf>Click 'Ok' to exit.";
   input $v, "Please enter the value to be converted (only numbers with decimals):", "1024";
   input $u, "Please enter the unit of that value (KB, MB, GB, TB, or PB/KBR/BB/B; 'BLANK'= raw!):", "MB";
   input $fu, "Now, the final unit you want (FLEX/FLEXR/KB, MB, GB, TB, or PB/KBR/BB/B/RAW):", "FLEX";
   $u = regexreplace($u, "BLANK", "");
   $a = formatbytes("$v $u", "raw", -1);
   $b = formatbytes("$a", "$fu", -1);
   echo "Original $v $u equals to $b.";
   copytext $b;
   status "Value on clipboard, too. Have a g'day!";
ToDo: error handling (anything that is not allowed = stop script!; now, let's try to learn some if/elseif/else coding...).
EDIT: Fixed misspelling.
EDIT 2:An improved version of this can be found here.
EDIT 3: Compatibility check added.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply