danrche Posted February 22, 2011 Share Posted February 22, 2011 Hello all, I'm trying to convert an integer like '1073741824' (which is = about 1BG in bytes) to a Float to look like 1GB Here's the code I've used in Vbscript '''''''''''''''' VBscript Function '''''''''''''''''''''' Function size(Bytes) If Bytes >= 1073741824 Then size = FormatNumber(Bytes \ 1024 \ 1024 \ 1024, 2) & " GB" End If End Function ''''''''''''''' End Vbscript '''''''''''''''''''''''''''''' but I don't know autoit enough to do the same. I just want a conversion function that i can pass my variables to and convert to a float for easier reading Thanks Ahead of time for your suggestions, recommendations, and help. also, how do I add tags for this post? Daniel Link to comment Share on other sites More sharing options...
enaiman Posted February 22, 2011 Share Posted February 22, 2011 This should do the trick for you: MsgBox(0, "", _ConvertToMyNeeds(102004578888)) Func _ConvertToMyNeeds($Number) Select Case $Number > 0 And $Number < 1024 Return $Number&" Bytes" Case $Number >= 1024 And $Number < 1048576 Return Round($Number/1024)&" KB" Case $Number >= 1048576 And $Number < 1073741824 Return Round($Number/1048576)&" MB" Case $Number >= 1073741824 Return Round($Number/1073741824)&" GB" EndSelect EndFunc If the values I have used for MB, GB ... are wrong, change them to the correct ones (I have used 1024, 1024^2, 1024^3 ...) SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
danrche Posted February 22, 2011 Author Share Posted February 22, 2011 enaiman, cool thanks, that's actually just what I'm looking to do. I was trying to do it with stringformat though, but couldn't figure it out, your way much easier Link to comment Share on other sites More sharing options...
kylomas Posted February 22, 2011 Share Posted February 22, 2011 danrche, This is a rough approximation following your VBScript code. Did NOT do any searching but imagine that you can find all kinds of routines in this forum. ; ; ; local $bytes = 9356922358, $size If $Bytes >= 1073741824 Then $size = $Bytes / 1024 / 1024 / 1024 & " GB" Endif consolewrite( $size & @lf) kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Yashied Posted February 22, 2011 Share Posted February 22, 2011 $iSize = 102004578888 $tData = DllStructCreate('wchar[80]') $Ret = DllCall('shlwapi.dll', 'ptr', 'StrFormatByteSizeW', 'uint64', $iSize, 'ptr', DllStructGetPtr($tData), 'uint', 80) MsgBox(0, '', DllStructGetData($tData, 1)) $Ret = DllCall('shlwapi.dll', 'ptr', 'StrFormatKBSizeW', 'uint64', $iSize, 'ptr', DllStructGetPtr($tData), 'uint', 80) MsgBox(0, '', DllStructGetData($tData, 1)) My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
danrche Posted February 22, 2011 Author Share Posted February 22, 2011 $iSize = 102004578888 $tData = DllStructCreate('wchar[80]') $Ret = DllCall('shlwapi.dll', 'ptr', 'StrFormatByteSizeW', 'uint64', $iSize, 'ptr', DllStructGetPtr($tData), 'uint', 80) MsgBox(0, '', DllStructGetData($tData, 1)) $Ret = DllCall('shlwapi.dll', 'ptr', 'StrFormatKBSizeW', 'uint64', $iSize, 'ptr', DllStructGetPtr($tData), 'uint', 80) MsgBox(0, '', DllStructGetData($tData, 1)) OOOO this is nice too, Thanks for the input. I never event looked at DLLCall before. Do you know how I can populate an array and sort on this? This is both learning and actual need for me. I'm trying to write an app much like dirsize that runs through your folders and spits out the top ten largest folders. I've been using logparser 2.2 with "Select Top 10 * into c:\bigfile.csv From C:\* order by size desc" =-i:FS -recurse:1 -o:csv it works great, but I don't want to install logparser on all the machines, plus I don't learn to code that way either Link to comment Share on other sites More sharing options...
danrche Posted February 22, 2011 Author Share Posted February 22, 2011 Answered some of my own questions here, #include <Array.au3> _ArrayAdd and _ArraySort Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now