RNJarvis
3/2/2017 - 11:36 AM

Write to a text file with the same name as the xdoc in the same folder as the xdoc

Write to a text file with the same name as the xdoc in the same folder as the xdoc

Private Sub WriteFile(ByVal pxdoc As CASCADELib.CscXDocument, sContents As String)
   Dim sBaseFolderPath As String
   Dim sBaseFileName As String
   Dim sTxtFullPath As String
   Dim sOperatorUserID As String
   Dim FSO As Object
   Dim iFreeFile As Integer

   OutputDebugString "KfxKTM_WriteFile: Start"

   On Error Resume Next

   Set FSO = CreateObject("Scripting.FileSystemObject")

   sBaseFolderPath = FSO.GetParentFolderName(pxdoc.FileName)
   sBaseFileName = FSO.GetBaseName(pxdoc.FileName)
   sTxtFullPath = FSO.BuildPath(sBaseFolderPath, sBaseFileName) & ".txt"

   OutputDebugString "KfxKTM_Checking if txt file already exists..."
   If FSO.FileExists(sTxtFullPath) = True Then
      OutputDebugString "KfxKTM_txt File exists, Deleting..."
      FSO.DeleteFile(sTxtFullPath, True)
      OutputDebugString "KfxKTM_txt File deleted, Checking..."
      If FSO.FileExists(sTxtFullPath) = True Then
         OutputDebugString "KfxKTM_Could not delete"
         Exit Sub
      End If
      OutputDebugString "KfxKTM_Delete Confirmed"
   End If

   iFreeFile = FreeFile
   Open sTxtFullPath For Append As #iFreeFile
   OutputDebugString "KfxKTM_Opened File for append"
   OutputDebugString "KfxKTM_Writing text contents values"

   Print #iFreeFile, sContents

   Close #iFreeFile
   OutputDebugString "KfxKTM_Closed file"
   OutputDebugString "KfxKTM_WriteFile: Finish"

End Sub