在 VB6 中,如何访问 FileSystem.GetFileInfo()?
In VB6, how to access FileSystem.GetFileInfo()?
旧项目的回归,需要使用 VB6。我在引用旧 VB6 IDE.
中包含 System.IO 的适当 DLL 时遇到问题
我已尝试引用:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll - 错误:无法添加对指定文件的引用
添加了对 C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb 的引用 - 不起作用。
添加了对 C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.tlb 的引用 - 智能感知中没有 System.IO。
有人可以 post 分步说明吗?
得到这个有点工作:
Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
Dim info As DiskInformation
Dim lAnswer As Long
Dim lpRootPathName As String
Dim lpSectorsPerCluster As Long
Dim lpBytesPerSector As Long
Dim lpNumberOfFreeClusters As Long
Dim lpTotalNumberOfClusters As Long
Dim lBytesPerCluster As Long
Dim lNumFreeBytes As Double
Dim dPercentFreeClusters As Double
Dim sString As String
lpRootPathName = "c:\"
lAnswer = GetDiskFreeSpace(lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters)
lBytesPerCluster = lpSectorsPerCluster * lpBytesPerSector
' Throws overflow exception - I guess there were no Terabyte drives when VB6 came around
' lNumFreeBytes = lBytesPerCluster * lpNumberOfFreeClusters
'sString = "Number of Free Bytes : " & lNumFreeBytes & vbCr & vbLf
'sString = sString & "Number of Free Kilobytes: " & (lNumFreeBytes / 1024) & "K" & vbCr & vbLf
'sString = sString & "Number of Free Megabytes: " & Format(((lNumFreeBytes / 1024) / 1024), "0.00") & "MB"
dPercentFreeClusters = Round(lpNumberOfFreeClusters / lpTotalNumberOfClusters * 100, 2)
但是,在尝试计算可用字节数时会抛出 Overflow
异常。
我想让它与 My.Computer.FileSystem
一起使用。建议?
旧项目的回归,需要使用 VB6。我在引用旧 VB6 IDE.
中包含 System.IO 的适当 DLL 时遇到问题我已尝试引用:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll - 错误:无法添加对指定文件的引用
添加了对 C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb 的引用 - 不起作用。
添加了对 C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.tlb 的引用 - 智能感知中没有 System.IO。
有人可以 post 分步说明吗?
得到这个有点工作:
Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
Dim info As DiskInformation
Dim lAnswer As Long
Dim lpRootPathName As String
Dim lpSectorsPerCluster As Long
Dim lpBytesPerSector As Long
Dim lpNumberOfFreeClusters As Long
Dim lpTotalNumberOfClusters As Long
Dim lBytesPerCluster As Long
Dim lNumFreeBytes As Double
Dim dPercentFreeClusters As Double
Dim sString As String
lpRootPathName = "c:\"
lAnswer = GetDiskFreeSpace(lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters)
lBytesPerCluster = lpSectorsPerCluster * lpBytesPerSector
' Throws overflow exception - I guess there were no Terabyte drives when VB6 came around
' lNumFreeBytes = lBytesPerCluster * lpNumberOfFreeClusters
'sString = "Number of Free Bytes : " & lNumFreeBytes & vbCr & vbLf
'sString = sString & "Number of Free Kilobytes: " & (lNumFreeBytes / 1024) & "K" & vbCr & vbLf
'sString = sString & "Number of Free Megabytes: " & Format(((lNumFreeBytes / 1024) / 1024), "0.00") & "MB"
dPercentFreeClusters = Round(lpNumberOfFreeClusters / lpTotalNumberOfClusters * 100, 2)
但是,在尝试计算可用字节数时会抛出 Overflow
异常。
我想让它与 My.Computer.FileSystem
一起使用。建议?