Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 26, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Convert File Size Into Proper Strings

Use this small API from the shlwapi (Shell Windowing API) DLL that ships with Internet Explorer (IE) to help you convert file size in bytes into proper strings such as "1.41 KB" or "1.32 MB." You need IE for this because it calls shlwapi.dll, which is present on all NT4, Windows 95+IE, and Windows 98 systems:

Private Declare Function StrFormatByteSize Lib _
	"shlwapi" Alias "StrFormatByteSizeA" (ByVal _
	dw As Long, ByVal pszBuf As String, ByRef _
	cchBuf As Long) As String

Public Function FormatKB(ByVal Amount As Long) _
	As String
	Dim Buffer As String
	Dim Result As String
	Buffer = Space$(255)
	Result = StrFormatByteSize(Amount, Buffer, _
	If InStr(Result, vbNullChar) > 1 Then
		FormatKB = Left$(Result, InStr(Result, _
			vbNullChar) - 1)
	End If
End Function
Deepu Chandy
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date