EmEditor (text editor) Forum Index
   Macro Samples
     Macro: Calculate HDD Size in MB from entered GB size
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
Stefan
Posted on: 4/9/2013 3:02 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Macro: Calculate HDD Size in MB from entered GB size
 
 
Do you want to create new partitions
with exactly n GB but you have to enter this in MB unit
because the Disk Management wants to get MB only?

If yes, this script will aid you.
It calculates the MB size from the entered GB (or TB) size:

Basically it's just a simple math:
n GB = n*1024 MB
n TB = n*1024*1024 MB

But since EmEditor is open anyway,
he can do the math for me:


//Calculate HDD Size in MB from entered GB
//  for creating new partitions in correct wanted size
//    because the Disk Management works with MB only

vInput = prompt("Enter GB size (add a 'T' for TB input) to calculate to MB :", "80");

vInput = vInput.toUpperCase();
vTest =  vInput.replace(/[A-Z ]/g,"");
if(vTest.length < 1){alert("Missing the size?\nUse e.g. 80 for 80GB or 80t for 80TB");quit();}

vInput = vInput.replace(/[A-FH-SU-Z ]/g,"");

if(vInput.indexOf("G") > 0){
	vInput = vInput.replace(/[A-Z ]/g, "");
	vResult = vInput * 1024;
	alert(vInput + " GB = " + vResult + " MB");
}else 
	if(vInput.indexOf("T") > 0){
	vInput = vInput.replace(/[A-Z ]/g, "");
	vResult = vInput * 1024 * 1024;
	alert(vInput + " TB = " + vResult + " MB");
}else{
	vInput = vInput.replace(/[A-Z ]/g, "");
	vResult = vInput * 1024;
	alert(vInput + " GB = " + vResult + " MB");
}


// 10 GB = 10240 MB
// 80 GB = 81920 MB
// 100 GB = 102400 MB
// 250 GB = 256000 MB
// 300 GB = 307200 MB
// 400 GB = 409600 MB
// 500 GB = 512000 MB
// 555 GB = 568320 MB
//1000 GB = 1024000 MB
//1024 GB = 1048576 MB
// 1 TB = 1048576 MB
// 80 TB = 83886080 MB


 
Flat Previous Topic | Next Topic


Subject Poster Date
 » Macro: Calculate HDD Size in MB from entered GB size Stefan 4/9/2013 3:02 am

Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文