VB Helper - Make extension methods to convert file sizes into strings giving sizes in KB, MB, etc. in Visual Basic .NET
"Title: Make extension methods to convert file sizes into strings giving sizes in KB, MB, etc. in Visual Basic .NET
Description: This example shows how to make extension methods to convert file sizes into strings giving sizes in KB, MB, etc. in Visual Basic .NET.
...
This example defines two extension methods for converting a file size in bytes into a value ending with an appropriate size such as KB, MB, or GB.
The first method uses the StrFormatByteSize API function.
..."
Funny the stuff you learn. I've got a code snip that I use everywhere for converting file sizes into a short human readable string. Any until today never knew there was a Windows API call, that's been available since Win2000, that does the same thing, StrFormatByteSize(A, W, EX, 64)
"Converts a numeric value into a string that represents the number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size. ...
The first parameter of this function has a different type for the ANSI and Unicode versions. If your numeric value is a DWORD, you can use StrFormatByteSize with text macros for both cases. The compiler will cast the numerical value to a LONGLONG for the Unicode case. If your numerical value is a LONGLONG, you should use StrFormatByteSizeW explicitly
532 -> 532 bytes
1340 -> 1.3KB
23506 -> 23.5KB
2400016 -> 2.4MB
2400000000 -> 2.4GB..."
LTL (Love To Learn :)
No comments:
Post a Comment
NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...
ALL comments are moderated. I will review every comment before it will appear on the blog.
Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...
I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...
Please see my comment policy for more information if you are interested.
Thanks,
Greg
PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...