寫文件操作(VB)

'写文件操作
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

你可能感兴趣的:(Visual,Basic)