Könnte jemand mal überprüfen ob der folgende Code unter Windows 98 funktioniert, da ich ihn als Tipp anmelden möchte. Bin XP Nutzer.
Option Explicit
'API's
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal _
lpFileName As String, _
ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As _
Long, _
ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, _
ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal _
dwMoveMethod As Long) As Currency
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
Long
'Konstanten
Private Const OPEN_EXISTING = 3
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_SHARE_READ = &H1
Private Const GENERIC_READ = &H80000000
Private Const FILE_END = 2
'Typen
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
' Koorekte Dateigrößen Angabe in KB MB oder Bytes
Public Function GrößeAlsString(ByRef curGröße As Currency) As String
If curGröße > 1073741824 Then
GrößeAlsString = nullprüfen(Round(CStr(curGröße / 1073741824), 2)) & " GB"
ElseIf curGröße > 1048576 Then
GrößeAlsString = nullprüfen(Round(CStr(curGröße / 1048576), 2)) & " MB"
ElseIf curGröße > 1024 Then
GrößeAlsString = nullprüfen(Round(CStr(curGröße / 1024), 2)) & " KB"
Else
GrößeAlsString = nullprüfen(CStr(curGröße)) & " Byte"
End If
End Function
Private Function nullprüfen(ByRef sZahl As String) As String
If Right$(sZahl, 1) = "0" Then
nullprüfen = Left$(sZahl, Len(sZahl) - 1)
Else
nullprüfen = sZahl
End If
End Function
Public Function DateiGröße(ByRef sDatei As String) As Currency
Dim lngHandle As Long
Dim curGröße As Currency
Dim dummy As SECURITY_ATTRIBUTES
dummy.bInheritHandle = True
dummy.lpSecurityDescriptor = 0
lngHandle = CreateFile(sDatei, GENERIC_READ, FILE_SHARE_READ, _
dummy, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&)
curGröße = SetFilePointer(lngHandle, 0, 0, FILE_END)
CloseHandle lngHandle
curGröße = ((curGröße - 922281240261610#) * 10000) - 7008
DateiGröße = curGröße
End Function
Private Function Round(ByVal nummer As String, _
Optional anzahl As Byte)
Dim n As Long
Dim n2 As Long
Dim tmp As Variant
' Ist Nummer eine Zahl?
If Not (IsNumeric(nummer)) Then
Round = 0: Exit Function
End If
' Ist Anzahl eine Zahl?
If Not (IsNumeric(anzahl)) Then
Round = 0: Exit Function
End If
' Wenn "." (Punkt) dann n=46
If (InStr(1, nummer, ".") > 0) Then
tmp = Split(nummer, ".")
n = 46
' Wenn "," (Komma) dann n=44
ElseIf (InStr(1, nummer, ",") > 0) Then
tmp = Split(nummer, ",")
n = 44
Else
Round = nummer: Exit Function
End If
If Len(tmp(1)) <= anzahl Then
Round = nummer: Exit Function
End If
' Wenn Anzahl = 0, Zahl vor dem Komma prüfen
If (anzahl = 0) Then
If Left$(tmp(1), 1) < 5 Then
' Wenn Zahl vor dem Komma kleiner 5,
' nicht runden!
Round = tmp(0)
Else
' Wenn Zahl größer 5, um eins erhöhen
Round = tmp(0) + 1
End If
Exit Function
End If
' Stelle (Anzahl+1) nach dem Komma abfragen
n2 = Mid$(tmp(1), anzahl + 1, 1)
If (n2 > 4) Then
Round = tmp(0) & Chr(n) & (Mid$(tmp(1), 1, anzahl) + 1)
ElseIf (n2 < 5) Then
Round = tmp(0) & Chr(n) & Mid$(tmp(1), 1, anzahl)
End If
End Function |