Navigation:  Introducing ThinBASIC >

Example 4

Previous pageReturn to chapter overviewNext page


This example load and scan an input file searching for lines starting with "TCC".

If any found, outputs a new file containing only such lines.




Uses "File"


Dim T1, T2     As Ext

Dim nLines     As Long

Dim sInData     As String Value File_Load( App_SourcePath + "Test_FileLineSelect(In).TXT" )

Dim sOutFile   As String Value "Test_FileLineSelect(Out).TXT"

Dim sOutput     As String

Dim sLines()   As String

Dim Count       As Long


'---Start timer



'---Determine the number of lines

nLines = ParseCount(sInData, $CRLF)


'---This function will parse the input string for $CRLF delimiters

'   filling and dimensioning sLines array

Parse sInData, sLines, $CRLF


'---Now scan the array in order to find whatever string

'   If string is found, corresponding line will be appended

'   to output buffer

For Count = 1 To nLines

If LEFT$(sLines(Count), 3) = "TCC" Then

   sOutput = sOutput + sLines(Count) + $CRLF

End If



'---Output buffer will be saved to output file

'   If file exists it is overwritten

File_Save(App_SourcePath + sOutFile , sOutput)


'---End timer

T2 = Timer


'---Show total time

MsgBox 0, "Total time: " + Format$(T2 - T1, "#0.0000") + " sec"