WriteText

Top  Previous  Next

 

The WriteText command allows you to write text to a new text file. A common use for this is to write information to custom data files or log files.

lamp Important: If the specified file already exists, it will be automatically overwritten. If the specified file is not a text file, the text will not be written and an error will be thrown.

Command Syntax

 

WriteText:[TargetFileName],[NewText],[NewLineOption]

 

The colon after the command and the comma sign between parameters are compulsory. Any additional spaces or characters will cause an error to be thrown. The command itself is not case sensitive, but parameters may be depending on the operating system and locale.

 

Parameters:

 

TargetFileName: The fully qualified path and file name of the file to which the text should be written

NewText: The text to be written to the file

NewLineOption: Text representing a valid NewLineOption which determines whether the text has new lines before or after the appended text.

 

The TargetFileName and NewText parameters are compulsory. If the parameter is missing an error will be thrown.

 

The NewLine parameter is optional. Valid values are:

 

None - no new line characters will be added. If you do not specify a parameter this is the default setting.

NewLineAfter - the NewLine character or character set for the current operating system will be added after the new text.

NewLineBeforeAndAfter - the NewLine character or character set for the current operating system will be added before and after the new text.a blank line will be added before  the remark text.

NewLineBeforeIfNotPresentAndAfter - the NewLine character or character set for the current operating system will be added before the new text if a Newline character does not already exist, and a further NewLine will be added after the text.

lamp Important: Because this is a new file, no Newline character will be added before the text regardless of which option you specify. If you specify any of the options above except None a Newline will be added after the text. There are two additional values in the NewLineOption enumeration: NewLineBefore and NewLineBeforeIfNotPresent. You can specify these options without an error being generated but they will be ignored and treated as if you specified the None option.

The TargetFileName parameter must be surrounded by quotation marks. The NewText parameter can be any text, but must have a value and must be surrounded by quotation marks if it contains any characters that could be detected as special characters, such as the colon, backslash, forward slash, etc.It is good practice to include the quotation marks in any case, so that it reduces the risk of error when writing scripts

 

Example:

 

Write text only:

 

WriteText:"C:\Test Text.txt","This is the new text"

 

Write text with a new line after:

 

WriteText:"C:\Test Text.txt","This is the new text",NewLineAfter

 

See Also: AppendText Special Functions Variables Subs