Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I convert bytes to KB

Tips -N- Tricks

How can I convert bytes to KB

by  ChrisRChamberlain  Posted    (Edited  )
If you need to express the size of a file in KB or MB as opposed to bytes, try the following :-
[color blue]
lnNo = ADIR(laFile,[C:\myApp\New App.exe])
IF lnNo = 1 [color green]&& File exists[color blue]
[tab]lcSize = Bytes2KB(laFile[2])
ENDI

? lcSize
[color green]
* ***************************
* Function: Bytes2KB
* Syntax: Bytes2KB(nValue)
* ***************************[color blue]
FUNCTION Bytes2KB
LPARAMETERS nValue

lnKB = (nValue/1.024) / 1000

IF lnKB > 999.99
[tab]RETURN TRANSFORM(CEILING(lnKB/1.024/1000),[999,999])+[ MB]
ELSE
[tab]RETURN TRANSFORM(CEILING(nValue/1.024/1000),[999,999])+[ KB]
ENDI
[color green]
*!* EOF
[color black]
Have fun

ChrisRChamberlain
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top