AnsweredAssumed Answered

Searching a txt file for a certain variant

Question asked by Robert Voogt on Jun 19, 2018
Latest reply on Jun 20, 2018 by Ivana Kolin

Hi all,

 

I use this code to look for the value of LogFile inside a txt file:

 

 

            LogFile = fso.GetBaseName(DrawFile)


            Dim strFilename As String: strFilename = "D:\Spare Part Generator\Log\Processed Assemblies.txt"
            Dim strTextLine As String
            Dim iFile As Integer: iFile = FreeFile
            Open strFilename For Input As #iFile
            Debug.Print strFilename & " Opened."
            Do Until EOF(1)
                Line Input #1, strTextLine
                Dim TempString As String
                TempString = UCase(Trim(strTextLine))
            
                If Left(TempString, 8) <> LogFile Then
                            'Start of opening drawing and running Macro
                            Set doc = swApp.OpenDoc6(DrawFile, swDocDRAWING, 2, "", fileerror, filewarning) '(FileName, Type, Options (2 = read only), Configuration, Errors, Warnings)
                            boolstatus = swApp.RunMacro2("D:\Spare Part Generator\Macro\MARS RDC.swp", "RDC", "main", swRunMacroDefault, False)
                            
                            'Writing name of assembly to Log
                            Set fso = CreateObject("Scripting.FileSystemObject")
                            Set oFile = fso.OpenTextFile("D:\Spare Part Generator\Log\Processed Assemblies.txt", 8, True) '8 = ForAppending
                            oFile.WriteLine LogFile & " - Date: " & Format(Date, "ddmmmyyyy") & " - Time: " & Format(Time, "HH:MM:SS")
                            oFile.Close
                            Set fso = Nothing
                            Set oFile = Nothing
                End If
            Loop
            Close #iFile

 

I do not get errors, but it does not look correctly in the txt file. the value of LogFile is present in the txt file but is not seen. Tempstring shows only the first sentence I added tot the file Processed Assemblies.txt.

Outcomes