Complex 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!)

Complex Unit Converter.

Post by SkyFrontier »

...a-hah!
-This one has error-checking so only allowed values can be entered!
-Has XY version checker!
-Based off this code.

Code: Select all

/*************************
//////////////////////////
//I grow powerful!!! ^^ //
//////////////////////////
*************************/
//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 for raw!):", "MB";
   if ($u == FLEX) { }
   elseif ($u == FLEXR) { }
   elseif ($u == KB) { }
   elseif ($u == MB) { }
   elseif ($u == GB) { }
   elseif ($u == TB) { }
   elseif ($u == PB) { }
   elseif ($u == KBR) { }
   elseif ($u == BB) { }
   elseif ($u == B) { }
   elseif ($u == RAW) { }
   elseif ($u == flex) { }
   elseif ($u == flexr) { }
   elseif ($u == kb) { }
   elseif ($u == mb) { }
   elseif ($u == gb) { }
   elseif ($u == tb) { }
   elseif ($u == pb) { }
   elseif ($u == kbr) { }
   elseif ($u == bb) { }
   elseif ($u == b) { }
   elseif ($u == raw) { }
   elseif ($u == blank) { }
   elseif ($u == BLANK) { }
   elseif ($u == "") { }
   else {
   end ($u =0), "Sorry - entered unit is NOT allowed!";
   }

   input $fu, "Now, the final unit you want (FLEX/FLEXR/KB, MB, GB, TB, or PB/KBR/BB/B/RAW):", "FLEX";
   $uu = regexreplace($u, "BLANK", ""); //error handling ; )
   $uu = regexreplace($uu, "RAW", ""); //strangely, "RAW" value leads to a script error.
   $uu = regexreplace($uu, "raw", ""); //strangely, "raw" value leads to a script error.
   $a = formatbytes("$v $uu", "raw", -1);
   $b = formatbytes("$a", "$fu", -1);
   echo "Original $v $uu equals to $b.";
   copytext $b;
   status "Value on clipboard, too. Have a g'day!";
ToDo: with regEx, this could(?) eliminate one of the 3 dialogs.
ToDo: learn regEx. :P
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...

EnjoyRC
Posts: 101
Joined: 08 Nov 2010 21:54

Re: Complex Unit Converter.

Post by EnjoyRC »

SkyFrontier wrote:ToDo: learn regEx. :P
RegEx Rocks!!!! Once I learned it, I use it daily. I had no idea what I was missin'

Where in XYplorer Scripting can you use RegEx besides regexreplace() ? I see that all your If ElseIfs.. can be replaced with one RegEx statement.

Code: Select all

If (Regex.IsMatch($u, "^(FLEX|KB|MB|FLEX|FLEXR|KB|MB|GBTB|PB|KBR|BB|B|RAW|flex|flexr|kb|mb|gb|tb|pb|kbr|bb|b|raw|blank|BLANK)$", RegexOptions.IgnoreCase))
But of course, this statement is VB.NET, not XYplorer.

Post Reply