开发者

conversion to MB does not work

开发者 https://www.devze.com 2023-02-10 09:48 出处:网络
I have the below code (which goes through the C: drive and gets file info data) and want to convert the length to a \"respectable\" number - i.e MB. The problem is that the line below does not do anyt

I have the below code (which goes through the C: drive and gets file info data) and want to convert the length to a "respectable" number - i.e MB. The problem is that the line below does not do anything to the code. Any help would be appreciated:

Line is: strlength = strlength * (1024 / 1024)

Private Sub btnclick_Click(ByVal sen开发者_Python百科der As System.Object, ByVal e As System.EventArgs) Handles btnclick.Click

    Dim strFilesinfo As System.IO.FileInfo
    Dim strlength As Double = 0
    Dim strname As String = ""

    For Each strFiles As String In My.Computer.FileSystem.GetFiles("c:\")

        strFilesinfo = My.Computer.FileSystem.GetFileInfo(strFiles)

        strlength = strFilesinfo.Length
        strname = strFilesinfo.Name

        strlength = strlength * (1024 / 1024)
        lstData.Items.Add(strname & " " & strlength)

    Next
End Sub

End Class


You're dividing by 1:

strlength = strlength * (1024 / 1024)

The parenthesis makes 1024 divided by 1024 happen first which equals 1.

Should be

strlength = strlength / 1024 / 1024
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号