Count Lines of Text File

This process displays the number of lines in a text file that the user has selected.

#Prompts the user to select the text file whose lines will be counted.

#The *.txt file filter makes sure that only files with the .txt extension will be available for selection.

#The "Check if file exists" option, makes sure that the the user will not enter a filename that does not correspond to an existing file.

Display.SelectFile Title:'Select the Text File' InitialDirectory:'' \
                    FileFilter:'*.txt' \
                    IsTopMost:False \
                    CheckIfFileExists:True \
                    SelectedFile=> SelectedTextFile \
                    ButtonPressed=> ButtonPressed
#Checks if the user pressed the "Open" button in the previous dialog. If not (i.e if the user pressed the "Cancel" button), the main body of the job will not be executed.

if ButtonPressed='Open' then
#Reads the text contained in the %SelectedTextFile% and stores it in the variable "FileContents" as a List, where each line of the text file will be an item of the list

File.ReadTextAsList File: SelectedTextFile \
                    Encoding:File.TextFileEncoding.UTF8 \
                    Contents=> FileContents
#Now, the "FileContents" variable, being a List, has a "Count" property, that represents the number of items in the list. All we have to do is display "FileContents.Count" to the user.

Display.ShowMessage Title:'Results' \
Message:'The file has '+FileContents.Count+ ' lines!' \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False ButtonPressed=> ButtonPressed
end
Display.ShowMessage Title:'Process Completed!' \
                    Message:'Process "Count Lines of Text File" completed.' \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed