Login | Register   
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
May 24, 2004

Convert the Filesize in a Number into String Format

This code converts the filesize in a number to string format—for instance, 1000 Bytes, 1 KB, etc.

Option Explicit

' Add a module and copy paste this function.
' To test this function, call this function from Immediate window by passing
' file size to it.  e.g. ?GetFileSizeString(1000), GetFileSizeString(10000)

Private Declare Function StrFormatByteSize Lib "shlwapi.dll" Alias "StrFormatByteSizeA" _
(ByVal dw As Long, ByVal szBuf As String, ByVal uiBufSize As Long) As Long

Private Function GetFileSizeString(ByVal lngFileSize As Long) As String
    Dim strBuff As String

    strBuff = Space$(100)
    StrFormatByteSize lngFileSize, strBuff, Len(strBuff)

    GetFileSizeString = Replace(Trim$(strBuff), vbNullChar, "")
End Function
Budhabhatti Mitesh
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap