warren2600
Programmer
need another pair of eyes to check out my code below.
i have several check and text boxes which calculate the size of a folder.
All of loops work, except one.
All of the if statements are the same.
i've added another variable in there just for the hell of it, and it calculates it correctly.
what am i missing?
thanks in advance for any input
warren
Private Function foldersize(sFolder As String, ndestination As Object)
Dim FindInfo As WIN32_FIND_DATA
Dim lFindHandle As Long
Dim lTemp As Long
Dim dSize As Double
Dim bNextLoop As Boolean
Dim sFileName As String
Dim fsize As Double
'Open up an API FIND on the folder.
lFindHandle = FindFirstFile(sFolder + "\*", FindInfo)
If lFindHandle <> INVALID_HANDLE_VALUE Then
Do
sFileName = FindInfo.cFileName
sFileName = Replace(sFileName, Chr(0), " ")
sFileName = Trim(sFileName)
If sFileName <> "." And sFileName <> ".." Then
If (FindInfo.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
'We're on a folder.
dSize = dSize + foldersize(sFolder + "\" + sFileName, ndestination)
Else
'We're on a file.
dSize = dSize + FindInfo.nFileSizeLow
dSize = dSize + (FindInfo.nFileSizeHigh * (2 ^ 16))
End If
End If
FindInfo.cFileName = String(255, vbNullChar)
lTemp = FindNextFile(lFindHandle, FindInfo)
bNextLoop = (lTemp <> ERROR_NO_MORE_FILES) And (lTemp <> 0)
Loop While bNextLoop
'Close down the file handle
FindClose lFindHandle
End If
fsize = fsize + dSize '--------> fsize isn't adding up
file_total = file_total + fsize '----------->another variable which i assign to another text box which works
Call returnsize(fsize, ndestination) 'call to next function to assign proper filesuffix
End Function
'----------------------------------------------'
' append suffix '
'----------------------------------------------'
Private Function returnsize(sSize As Double, ByVal ndestination As Object)
Dim filesuffix As String
If sSize > 1024 Then
sSize = sSize / 1024
filesuffix = " KB"
If sSize > 1024 Then
sSize = sSize / 1024
filesuffix = " MB"
If sSize > 1024 Then
sSize = sSize / 1024
filesuffix = " GB"
End If
End If
End If
ndestination = Format(sSize, "###0.00") & filesuffix
End Function
i have several check and text boxes which calculate the size of a folder.
All of loops work, except one.
All of the if statements are the same.
i've added another variable in there just for the hell of it, and it calculates it correctly.
what am i missing?
thanks in advance for any input
warren
Private Function foldersize(sFolder As String, ndestination As Object)
Dim FindInfo As WIN32_FIND_DATA
Dim lFindHandle As Long
Dim lTemp As Long
Dim dSize As Double
Dim bNextLoop As Boolean
Dim sFileName As String
Dim fsize As Double
'Open up an API FIND on the folder.
lFindHandle = FindFirstFile(sFolder + "\*", FindInfo)
If lFindHandle <> INVALID_HANDLE_VALUE Then
Do
sFileName = FindInfo.cFileName
sFileName = Replace(sFileName, Chr(0), " ")
sFileName = Trim(sFileName)
If sFileName <> "." And sFileName <> ".." Then
If (FindInfo.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
'We're on a folder.
dSize = dSize + foldersize(sFolder + "\" + sFileName, ndestination)
Else
'We're on a file.
dSize = dSize + FindInfo.nFileSizeLow
dSize = dSize + (FindInfo.nFileSizeHigh * (2 ^ 16))
End If
End If
FindInfo.cFileName = String(255, vbNullChar)
lTemp = FindNextFile(lFindHandle, FindInfo)
bNextLoop = (lTemp <> ERROR_NO_MORE_FILES) And (lTemp <> 0)
Loop While bNextLoop
'Close down the file handle
FindClose lFindHandle
End If
fsize = fsize + dSize '--------> fsize isn't adding up
file_total = file_total + fsize '----------->another variable which i assign to another text box which works
Call returnsize(fsize, ndestination) 'call to next function to assign proper filesuffix
End Function
'----------------------------------------------'
' append suffix '
'----------------------------------------------'
Private Function returnsize(sSize As Double, ByVal ndestination As Object)
Dim filesuffix As String
If sSize > 1024 Then
sSize = sSize / 1024
filesuffix = " KB"
If sSize > 1024 Then
sSize = sSize / 1024
filesuffix = " MB"
If sSize > 1024 Then
sSize = sSize / 1024
filesuffix = " GB"
End If
End If
End If
ndestination = Format(sSize, "###0.00") & filesuffix
End Function