I don't recognize that code as mine and if I did I would deny it. :P
Instead of all those IF constructs, a SELECT CASE construct would be more efficient since they are mutually exclusive. As for the Trim(), I misconstrued what you are trying to do. It looks like you want the entire line but without the leading spaces. If that is the case, LTrim() as Howard suggested is all you need.
Here is your code with some small changes:
Code:
break on
$null = SetOption ("NoVarsInStrings","On")
$null = SetOption ("Explicit","On")
Dim $file,$filehandle,$namevalue,$line,$name,$namearray,$null,$outputfile,$outputhandle
$file = 'c:\kix\test_text.txt'
$filehandle = FreeFileHandle()
If Open ($filehandle,$file) = 0
$namevalue = 0
While @Error = 0
$line = ReadLine ($filehandle)
Select
Case InStr ($line,'DCS Application Snapshot')
ReDim Preserve $namearray[$namevalue]
$namearray[$namevalue] = LTrim($line)
$namevalue = $namevalue+1
Case InStr ($line,'Authorization')
ReDim Preserve $namearray[$namevalue]
$namearray[$namevalue] = LTrim($line)
$namevalue = $namevalue+1
Case InStr ($line,'Inbound communication address')
ReDim Preserve $namearray[$namevalue]
$namearray[$namevalue] = LTrim($line)
$namevalue = $namevalue+1
Case InStr ($line,'Outbound communication address')
ReDim Preserve $namearray[$namevalue]
$namearray[$namevalue] = LTrim($line)
$namevalue = $namevalue+1
Case InStr ($line,'Application name')
ReDim Preserve $namearray[$namevalue]
$namearray[$namevalue] = LTrim($line)
$namevalue = $namevalue+1
Case InStr ($line,'Application status')
ReDim Preserve $namearray[$namevalue]
$namearray[$namevalue] = LTrim($line)
$namevalue = $namevalue+1
EndSelect
Loop
$null = Close ($filehandle)
$outputfile = 'c:\kix\test_text_out.txt'
$outputhandle = FreeFileHandle()
If Exist ($outputfile)
Del $outputfile
EndIf
If $namearray[0] <> ''
If Open ($outputhandle,$outputfile,5) = 0
For Each $name In $namearray
$null = WriteLine ($outputhandle,$name+@CRLF)
Next
$null = Close ($outputhandle)
Else
$null = MessageBox ('Unable To Create '+$outputfile,'Error',0)
EndIf
EndIf
Else
$null = MessageBox ('Unable To Open '+$file,'Error',0)
EndIf
I would rethink your loop however. There is an inherent flaw with looping on @Error=0 when you perform other functions within the loop that can throw @Error. It can end your loop pre-maturely. By readning in the file into an array first and then looping thru the array, it is mitigated.