Indigo Rose Software
  #1  
Old 2 Weeks Ago
SteevieNiteHeat SteevieNiteHeat is offline
Forum Member
 
Join Date: Jun 2008
Posts: 89
Convert MB to GB??

Hi!
In my Project I have the following code to show the drive's free space in a table:
Code:
cSpFree = Drive.GetFreeSpace("C:");
cspace = Drive.GetSize("C:");
Label.SetText("cSpace", cSpFree.." MB");
BUT, being the result is in MegaBytes, how do I make it display GigaBytes if there is at least 1GB free space and MB if there is less?

Also, basically the same question for another part, Im using the following code to show the free memory:
Code:
tbMemory = System.GetMemoryInfo();
Label.SetText("MemoryFree", tbMemory.AvailableRAM.." MB");
With the same question, if I have 1GB of free memory show it in GB, but if under 1GB then show free memory in MB?

Thanks!

This is part of a sorta quick access pannel I have made for my lappy to stay on top at the top of the screen with usefull shortcuts, mostly using the NirCmd command line app that was introduced to me from a thread on this forum which has helped me no end

Last edited by SteevieNiteHeat; 2 Weeks Ago at 05:28 PM. Reason: typo's corrected
Reply With Quote
  #2  
Old 2 Weeks Ago
Scriptonite's Avatar
Scriptonite Scriptonite is offline
Indigo Rose Customer
 
Join Date: Oct 2009
Location: 127.0.0.1
Posts: 41
you need to divide the total by 1000 for gigs. Here's two ways you can do it.

Code:
cSpFree = Drive.GetFreeSpace("C:");
cspace = Drive.GetSize("C:");

GBspace=cspace/1000
GBFree = cSpFree/1000

if GBFree < 1
then
Label.SetText("cSpace", cSpFree.." MB out of "..GBspace.." free");
else

Label.SetText("cSpace", GBFree.." GB out of "..GBspace.." free");
end
or


Code:
function LeftOverMegs(Gigs,TotalMegs)
return Math.Round(TotalMegs - (Gigs*1000), 0);
end


cSpFree = Drive.GetFreeSpace("C:");
cspace = Drive.GetSize("C:");

GBspace =cspace/1000
GBFree = cSpFree/1000

TotalGigs = Math.Round(GBspace, 0);
FreeGigs = Math.Round(GBFree, 0);


TotalMegs = LeftOverMegs(TotalGigs,cspace)
FreeMegs = LeftOverMegs(FreeGigs,cSpFree)



Label.SetText("cSpace", FreeGigs.."GB and "..FreeMegs.."MB out of "..TotalGigs.."GB and "..TotalMegs.."MB free");
You should be able to adjust this to your needs.
__________________
User error: replace user and press any key to continue.
Reply With Quote
  #3  
Old 2 Weeks Ago
SteevieNiteHeat SteevieNiteHeat is offline
Forum Member
 
Join Date: Jun 2008
Posts: 89
Brilliant, thank you so much for your reply :-)
Reply With Quote
  #4  
Old 2 Weeks Ago
Scriptonite's Avatar
Scriptonite Scriptonite is offline
Indigo Rose Customer
 
Join Date: Oct 2009
Location: 127.0.0.1
Posts: 41
Glad I could help
__________________
User error: replace user and press any key to continue.
Reply With Quote
  #5  
Old 2 Weeks Ago
mystica's Avatar
mystica mystica is offline
Forum Member
 
Join Date: May 2007
Location: Sydney, Australia
Posts: 330
Quote:
Originally Posted by Scriptonite View Post
you need to divide the total by 1000 for gigs ...
Divide by 1024, not 1000.
(ie. 1 gigabyte = 1024 megabytes)
Reply With Quote
  #6  
Old 2 Weeks Ago
Scriptonite's Avatar
Scriptonite Scriptonite is offline
Indigo Rose Customer
 
Join Date: Oct 2009
Location: 127.0.0.1
Posts: 41
Doh, my bad. Thanks for catching that mystica. Not sure where my brain went to there..........
__________________
User error: replace user and press any key to continue.
Reply With Quote
  #7  
Old 2 Weeks Ago
Sakuya's Avatar
Sakuya Sakuya is offline
Forum Member
 
Join Date: Oct 2009
Posts: 115
Didn't anyone think of String.GetFormattedSize?
Reply With Quote
  #8  
Old 2 Weeks Ago
Scriptonite's Avatar
Scriptonite Scriptonite is offline
Indigo Rose Customer
 
Join Date: Oct 2009
Location: 127.0.0.1
Posts: 41
of course not, that's the easy way. That would have been simpler, but then i would have never been able to write that out in wrong division...........
__________________
User error: replace user and press any key to continue.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -6. The time now is 08:31 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software