Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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, _
		Len(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.

 

 

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