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

📄 mtextfileaccess.bas

📁 vb做的网易评论自动采集软件
💻 BAS
字号:
Attribute VB_Name = "mTextFile"
Option Explicit

Public Function ReadTextFile(ByVal sPath As String, Optional ByVal lSize As Long) As String
On Error GoTo ErrHandle
    
        Dim lFileNum As Long
        Dim lFileSize As Long
        lFileNum = FreeFile
        Open sPath For Input As lFileNum
        lFileSize = LOF(lFileNum)
        If lSize > 0 And lFileSize > lSize Then lFileSize = lSize
        ReadTextFile = StrConv(InputB(lFileSize, lFileNum), vbUnicode)
        Close lFileNum
    
    Exit Function
ErrHandle:
    If Err.Number <> 0 Then
        If Err.Number = 53 Then Exit Function
        'MsgBox "Error " & Err.Number & vbCrLf & Err.Description, vbExclamation, "读文件错误": Exit Function
    End If
End Function

Public Function WriteTextFile(ByVal sPath As String, ByVal strString As String, Optional ByVal blnAppend As Boolean = False) As Long
On Error GoTo ErrHandle
    Dim lFileNum As Long
    lFileNum = FreeFile
    If blnAppend = True Then
        Open sPath For Append As lFileNum
        Print #lFileNum, strString
    Else
        Open sPath For Output As lFileNum
        Print #lFileNum, strString
    End If
    Close lFileNum
    WriteTextFile = 0
    
    Exit Function
ErrHandle:
    WriteTextFile = Err.Number
End Function

Public Function FileExists(ByVal Filename As String) As Boolean
    On Error Resume Next
        FileExists = Dir$(Filename) <> ""
        If Err.Number <> 0 Then
            FileExists = False
        End If
    On Error GoTo 0
End Function

Public Function GetFileCheckSum(ByVal sPath As String) As Long
On Error GoTo ErrHandle
If FileExists(sPath) = False Then Exit Function
    Dim lFileNum As Long
    Dim lngOutput As Long
    Dim lngByte As Byte
    Dim i As Long
    lFileNum = FreeFile
    Open sPath For Random As lFileNum Len = 1
        For i = 1 To LOF(1) Step 10
            Get lFileNum, i, lngByte
            lngOutput = lngOutput + lngByte
            If lngOutput > 1000000000 Then lngOutput = 0
        Next i
    Close lFileNum
    GetFileCheckSum = lngOutput

    Exit Function
ErrHandle:
    If Err.Number <> 0 Then
        If Err.Number = 53 Then Exit Function
        'MsgBox "Error " & Err.Number & vbCrLf & Err.Description, vbExclamation: Exit Function
    End If
    
End Function

⌨️ 快捷键说明

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