⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 55.txt

📁 VB文章集(含API、窗口、数据库、多媒体、系统、文件、等等)
💻 TXT
字号:
将文件大小变成相应的字符串

Shlwapi.dll是一个跟随IE一起发行的文件。利用该文件中的一个API函数,你就可
以将以字节显示的文件的大小转变成相应的字符串。例如:"1.41 KB" 或 "1.32 
MB." 在NT4, Windows 95+IE, 以及 Windows 98 这几个操作系统中都能找到
Shlwapi.dll文件。

下面是完整的源程序:

Option Explicit 

Private Declare Function StrFormatByteSize Lib "shlwapi" Alias "
StrFormatByteSizeA" (ByVal dw As Long, ByVal pszBuf As String, ByRef 
cchBuf As Long) As String 
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long,
lpFileSizeHigh As Long) As Long 
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As 
String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long 
Private Const OFS_MAXPATHNAME = 128 
Private Type OFSTRUCT 
cBytes As Byte 
fFixedDisk As Byte 
nErrCode As Integer 
Reserved1 As Integer 
Reserved2 As Integer 
szPathName(OFS_MAXPATHNAME) As Byte 
End Type 
Private Const OF_READ = &H0 

Private Sub Form_Load() 
Dim FileHandle As Long 
Dim strFileName As String 
Dim leRpOpenBuff As OFSTRUCT 
strFileName = "c:\autoexec.bat" 
FileHandle = OpenFile(strFileName, leRpOpenBuff, OF_READ) 
Dim lngFileSize As Long 
Dim temp As Long 
temp = GetFileSize(FileHandle, lngFileSize) 

MsgBox FormatKB(temp), vbInformation, "File Size in String" 

End Sub 

Public Function FormatKB(ByVal Amount As Long) As String 

Dim Buffer As String 
Dim Result As String 

Buffer = Space$(255) 

Result = StrFormatByteSize(Amount, Buffer, Len(Buffer)) 

If InStr(Result, vbNullChar) > 1 Then 
FormatKB = Left$(Result, InStr(Result, vbNullChar) - 1) 

End If 

End Function 


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -