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
May 25, 2004



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

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.



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