File Operation in Rational Robot (2)

xiaoxiao2021-03-06  52

2) Write files 1, sequential file write sequence file We can use the Write # and Print # statements to write data to a file already opened. The following is their format and description: Print # syntax format: Print # file number, Variable lists For example, write text in the text box to the file, the code is as follows: Open "file.txt" for output as #filenuminput #filenum, text1.text write "syntax format: Write # file number, Variable list description : Use the information written by WRITE # statement for easy reading with the input # statement, because the Write # statement automatically writes the information in the file to separately separate, and double quotes for string data. For example: Open "Student.txt" for Output as #filenumwrite #filenum, "Zhang San", "First First Grade", 14write #filenum, "Lee 4", "Professional High School", 18 2, Random Document Write data to random files Using the PUT # statement. The syntax format is as follows: PUT [#] filenum, [recnum], userType Description: (1) filenum is the file number to open; recnum is the record number to be written, if omitted, then it will last Writes in the latter record written by the records written by GET and PUT statements. If the GET and PUT statements are not executed, starting from the first record (2) Usertype is a user-defined user-defined user-defined. Data type variables. For example, we write data to the 5th record in the front student.txt file, available: stud .no = 0301stud.name = "Wang Wu" stud.age = 20PUT # 1, 5, If the data to be inserted is not only one or two, first determine the file and the length of each record, so how many records can be calculated in the file. We can use the LOF () function to return the length of the file, LEN ( The function returns the length of each record, and the number of records in the calculation file can be divided by the length of the file to a record length. Example is as follows: NextRec = (Lof (1) / len (use)) 1PUT # 1, NextRec, UserType 3, the binary below is a statement format written in binary mode and its description: Format: PUT [#] FileNumber, [POS], VAR function: use binary In the way, it is written from the position specified in the file, and the data description of the measured variable length: (1) filenumber is the file number open in binary mode. (2) POS is used to specify the byte position when the write operation occurs. If omitted, use the current file pointer position. (3) VAR is a variable used to store the written data. This statement automatically writes the file according to the byte length contained in the VAR variable, if Var is a variable length character The string variable, the number of bytes transmitted is equal to the current number of the current bytes in VAR. Use the method to refer to the read operation of the binary file.

The above is a summary of file operations in Rational Robot, welcome everyone to communicate!

转载请注明原文地址:https://www.9cbs.com/read-115701.html

New Post(0)