简体   繁体   English

转换为MB不起作用

[英]conversion to MB does not work

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 - ie MB. 我有以下代码(通过C:驱动器并获取文件信息数据),并希望将长度转换为“可指定”的数字-即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) 行是:strlength = strlength *(1024/1024)

Private Sub btnclick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclick.Click 私有Sub btnclick_Click(ByVal发送者为System.Object,ByVal e为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

End Class 末级

You're dividing by 1: 您被1除

strlength = strlength * (1024 / 1024)

The parenthesis makes 1024 divided by 1024 happen first which equals 1. 括号使1024除以1024首先等于1。

Should be 应该

strlength = strlength / 1024 / 1024

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM