... und wieder ein kleiner Codeschnipsel.
Diese Prozedur wandelt eine Byteangabe in die sinnvoll größte Einheit um und hängt diese dann auch dahinter. Angaben kleiner als 0, wie sie zum Beispiel von FileSize() wiedergegeben werden, werden von der Prozedur ignoriert. Macht manuelle If-Abfragen unnötig.
Die Rückgabe erfolgt (natürlich) als String.
Code: Alles auswählen
Procedure.s byterechner(byte.f, nachkommastellen.l)
	;	© AND-Software, 2006
	Protected temp$
	If byte < 0
		ProcedureReturn ""
	EndIf
	If byte < 1024
		byte=byte
		temp$="Byte"
		nachkommastellen=0
	EndIf
	If byte >= 1024
		byte=byte/1024
		temp$="KB"
	EndIf
	If byte >= 1024
		byte=byte/1024
		temp$="MB"
	EndIf
	If byte >= 1024
		byte=byte/1024
		temp$="GB"
	EndIf
	If byte >= 1024
		byte=byte/1024
		temp$="TB"
	EndIf
	ProcedureReturn StrF(byte, Abs(nachkommastellen))+" "+temp$
EndProcedure
Debug byterechner(FileSize("about:blank"), 2) ; nichts, da nicht existent/keine Größe
Debug byterechner(75991, 1)                   ; ca. 75 KB
Debug byterechner(12*1024*1024+339, 0)        ; ca. 12 MB