寫文件操作(VB)

来源:互联网 发布:java对象的创建过程 编辑:程序博客网 时间:2024/05/04 17:46
'写文件操作
Public Function WriteFile(strWhat As String, strFilePath As String, strFileName As String) As Boolean
     WriteFile = False
     Dim fso As New FileSystemObject
     Dim fFile As File
     Dim ts As TextStream
     On Error GoTo ErrorHandl
    
     Dim txtFile As String
     Dim intFlag As Integer
    
     txtFile = strFilePath & strFileName
     intFlag = 8
    
     If fso.FileExists(txtFile) = False Then
        fso.CreateTextFile txtFile, True
        intFlag = 2
     End If
     Set fFile = fso.GetFile(txtFile)
    
     Set ts = fFile.OpenAsTextStream(intFlag, -2)
     ts.WriteLine (strWhat)
     ts.Close
     WriteFile = True
    Exit Function
ErrorHandl:
End Function
原创粉丝点击