Command: TextFileOpen
- Updated2023-02-21
- 4 minute(s) read
Command: TextFileOpen
Opens or creates a text file.
Input Parameters
FileName |
Specifies the file name. |
TextFileAttribute |
Specifies how DIAdem creates or opens a text file. You can connect various attributes with logic operators. |
[TextFileLineEnd] |
Specifies the line end character. |
Return Parameters
ReturnValue |
Contains the file handle as a numeric value. If an error occurs when the text file is being opened or created, the function returns the value -1. The return value is a TextFileHandle type. |
You can open a text file faster if you specify the character encoding with the TextFileEOL function and transfer it to the TextFileOpen function.
Examples
The following example creates a text file in ANSI code and writes twenty lines in this file. DIAdem saves the file in the DIAdem script folder.
| VBScript | Python |
Dim LineNo, intMyHandle, intMyText, intMyError intMyHandle = TextFileOpen(ScriptReadPath & "NewText.txt", eTextFileAttributeCreate OR eTextFileAttributeWrite OR eTextFileAttributeANSI) For LineNo = 1 To 20 intMyText= TextfileWriteLn(intMyHandle, "Line " & LineNo) Next intMyError = TextFileClose(intMyHandle)
The following example reads a text file in ANSI code.
| VBScript | Python |
Dim strFile, intLineCount, intMyHandle, strEOL, strMyText, intMyError strFile = ScriptReadPath & "NewText.txt" strEOL = TextFileEOL(strFile) intMyHandle = TextFileOpen(strFile, eTextFileAttributeRead, strEOL) intLineCount = 0 Do strMyText = TextFileReadLn(intMyHandle) If (Not IsNull(strMyText)) then intLineCount = intLineCount+1 Call MsgBoxDisp(strMyText,"MB_OK") End If Loop until (IsNull(strMyText)) intMyError = TextFileClose(intMyHandle)
![]() | Note If you open a file with the filename extension .Lst, DIAdem opens this file for the Serial evaluation. DIAdem automatically accesses the files that have the same name as the script file, but have the filename extension .Lst. Therefore, you must open this file with the TfDenyNone attribute. |
Related Topics
Command: ExecuteExclusiveBegin | Command: ExecuteExclusiveEnd | Command: ExecuteExclusiveEndAll


