devxlogo

Convert the Filesize in a Number into String Format

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 LongPrivate 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
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist