转换为MB不起作用

时间:2011-02-15 15:55:00

标签: vb.net visual-studio-2010

我有以下代码(通过C:驱动器并获取文件信息数据)并希望将长度转换为“可敬”的数字 - 即MB。问题是下面的代码行不对代码做任何事情。任何帮助将不胜感激:

行是:strlength = strlength *(1024/1024)

Private Sub btnclick_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理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

结束班

1 个答案:

答案 0 :(得分:4)

你除以1:

strlength = strlength * (1024 / 1024)

括号使1024除以1024先发生,等于1。

应该是

strlength = strlength / 1024 / 1024