Monday, October 30, 2017

To clear all variable/data from the text file

Function fnClear_Data_From_TextFile(strFilePath)
   'Function to clear all variable/data from the text file
   On Error Resume Next 'Error Handling
'Constants for Reading and Tristate Use Default
Const ForReading = 1,ForWriting= 2,ForAppending = 8
    'Path of the file to be modified
'strFilePath = Environment("Env_TestData_TextFile")
    'Create FSO Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FileExists(strFilePath) Then
Call DoneResult("Specified file: '" & strFilePath & "' does not exist", "Not able to clear total contents from text file")
fnClear_Data_From_TextFile = ""
Exit Function
End If
'Get the file to be read.
Set objGetFile = objFSO.GetFile(strFilePath)
If objGetFile.Size <> 0 Then
        Set objTextFile = objGetFile.OpenAsTextStream(ForWriting,False)
        objTextFile.Close
Call DoneResult("Data is successfully deleted from the file: '" & strFilePath & "'", "Text file contents are deleted successfully")
Exit Function
End If
If Err.Number <> 0  Then
Call DoneResult("Exception error " & Err.Number & " with the description " & Err.Description & " occured while clearing all data from Text file", "Emptying text file is failed")
fnGet_Value_From_TextFile = ""
End If
End Function

No comments:

Post a Comment