• No results found

DAT Files

In document msoptbasiccompilerv3.04 (Page 152-158)

5.20 File Manipulation

5.20.1 DAT Files

This one has a sequential file structure, which is much like the ordinary sequential file but is modified to support FIFO structure. We call this type of file as DAT file. Because DAT files are usually used to store transaction data, they are also referred to as Transaction files. The length of each record in the transaction file is limited to 250 bytes. For portable terminals, a BASIC program can have up to 6 transaction files.

DEL_TRANSACTION_DATA

Purpose To remove a block of transaction data from the default transaction file.

Syntax DEL_TRANSACTION_DATA(N%)

Remarks This command will only have an effect on the first (default) transaction file.

"N%" is an integer variable, determining how many transaction records to be deleted and how to delete.

If "N%" is a positive integer, the specified number of records will be deleted from the top of the transaction file 1, i.e. the oldest records will be deleted.

If "N%" is a negative integer, the specified number of records will be deleted from the bottom of the transaction file 1, i.e. the latest records will be deleted.

Example ...

PRINT "Discard the latest transaction? (Y/N)"

...

Loop:

KeyData$ = INKEY$

IF KeyData$ = "" THEN GOTO Loop

ELSE IF KeyData$ = "Y" THEN DEL_TRANSACTION_DATA(-1) END IF

...

See Also DEL_TRANSACTION_DATA_EX, EMPTY_TRANSACTION

DEL_TRANSACTION_DATA_EX

Purpose To remove a block of transaction data from a specified transaction file.

Syntax DEL_TRANSACTION_DATA_EX(file%, N%)

Remarks "file%" is an integer variable in the range of 1 to 6, indicating which transaction file the command is to affect. The command DEL_TRANSACTION_DATA_EX(1, N%) works the same as the command DEL_TRANSACTION_DATA(N%).

"N%" is an integer variable, determining how many transaction records to be deleted and how to delete.

If "N%" is a positive integer, the specified number of records will be deleted from the top of the transaction file 1, i.e. the oldest records will be deleted.

If "N%" is a negative integer, the specified number of records will be deleted from the bottom of the transaction file 1, i.e. the latest records will be deleted.

Example ...

PRINT "Discard the latest transaction? (Y/N)"

...

Loop:

KeyData$ = INKEY$

IF KeyData$ = "" THEN GOTO Loop

ELSE IF KeyData$ = "Y" THEN

DEL_TRANSACTION_DATA_EX(TransFile%, -1) END IF

...

See Also DEL_TRANSACTION_DATA, EMPTY_TRANSACTION_EX

EMPTY_TRANSACTION

Purpose To remove all the transaction data from the default transaction file.

Syntax EMPTY_TRANSACTION

Remarks This command will only have an effect on the first (default) transaction file.

Example …

PRINT “Remove all the transaction data? (Y/N)”

… Loop:

KeyData$ = INKEY$

IF KeyData$ = “” THEN GOTO Loop

ELSE IF KeyData$ = “Y” THEN EMPTY_TRANSACTION

END IF

See Also DEL_TRANSACTION_DATA, EMPTY_TRANSACTION_EX

EMPTY_TRANSACTION_EX

Purpose To remove all the transaction data from a specified transaction file.

Syntax EMPTY_TRANSACTION_EX(file%)

Remarks "file%" is an integer variable in the range of 1 to 6, indicating which transaction file the command is to affect. The command EMPTY_TRANSACTION_EX(1) works the same as the command EMPTY_TRANSACTION.

Example EMPTY_TRANSACTION_EX(6)

See Also DEL_TRANSACTION_DATA_EX, EMPTY_TRANSACTION

GET_TRANSACTION_DATA$

Purpose To read a transaction record from the default transaction file.

Syntax A$ = GET_TRANSACTION_DATA$(N%)

Remarks "A$" is a string variable to be assigned to the transaction data.

"N%" is an integer variable, indicating the ordinal number of the record to be read from the first transaction file.

Example ...

WHILE (TRANSACTION_COUNT > 0)

TransactionData$ = GET_TRANSACTION_DATA$(1) WRITE_COM(1, TransactionData$)

DEL_TRANSACTION_DATA(1) WEND

See Also GET_TRANSACTION_DATA_EX$, SAVE_TRANSACTION, UPDATE_TRANSACTION

GET_TRANSACTION_DATA_EX$

Purpose To read a transaction record from a specified transaction file.

Syntax A$ = GET_TRANSACTION_DATA_EX$(file%, N%) Remarks "A$" is a string variable to be assigned to the transaction data.

"file%" is an integer variable in the range of 1 to 6, indicating which transaction file to access. The command GET_TRANSACTION_DATA_EX$(1,1) works the same as the command GET_TRANSACTION_DATA$(1).

"N%" is an integer variable, indicating the ordinal number of the record to be read from the first transaction file.

Example ...

WHILE (TRANSACTION_COUNT > 0)

TransactionData$ = GET_TRANSACTION_DATA_EX$(TransFile%,1) WRITE_COM(1, TransactionData$)

DEL_TRANSACTION_DATA_EX(TransFile%,1) WEND

See Also GET_TRANSACTION_DATA$, SAVE_TRANSACTION_EX UPDATE_TRANSACTION_EX

SAVE_TRANSACTION

Purpose To save (append) a transaction record to the default transaction file.

Syntax SAVE_TRANSACTION(data$)

Remarks "data$" is a string variable, representing the string to be saved in the first (default) transaction file.

Example ON READER(1) GOSUB BcrData_1 ...

BcrData_1:

Data$ = GET_READER_DATA$(1) PRINT Data$

SAVE_TRANSACTION(Data$)

IF GET_FILE_ERROR <> 0 THEN PRINT "Transaction not saved."

RETURN

See Also GET_TRANSACTION_DATA$, SAVE_TRANSACTION_EX, UPDATE_TRANSACTION

SAVE_TRANSACTION_EX

Purpose To save (append) a transaction record to a specified transaction file.

Syntax SAVE_TRANSACTION_EX(file%, data$)

Remarks "file%" is an integer variable in the range of 1 to 6, indicating which transaction file to access. The command SAVE_TRANSACTION_EX(1,data$) works the same as the command SAVE_TRANSACTION(data$).

"data$" is a string variable, representing the string to be saved in the specified transaction file.

Example ON READER(1) GOSUB BcrData_1 ...

BcrData_1:

BEEP(2000,5)

Data$ = GET_READER_DATA$(1) PRINT Data$

SAVE_TRANSACTION_EX(TransFile%,Data$)

IF GET_FILE_ERROR <> 0 THEN PRINT "Transaction not saved."

RETURN

See Also GET_TRANSACTION_DATA_EX$, SAVE_TRANSACTION, UPDATE_TRANSACTION_EX

TRANSACTION_COUNT

Purpose To get the total number of transaction records saved in the first (default) transaction file.

Syntax A% = TRANSACTION_COUNT

Remarks "A%" is an integer variable to be assigned to the result.

Example ...

DataCount:

DataCount% = TRANSACTION_COUNT CLS

PRINT DataCount%, "Transaction data is saved."

RETURN ...

See Also TRANSACTION_COUNT_EX

TRANSACTION_COUNT_EX

Purpose To get the total number of transaction records saved in a specified transaction file.

Syntax A% = TRANSACTION_COUNT_EX(file%)

Remarks "A%" is an integer variable to be assigned to the result.

"file%" is an integer variable in the range of 1 to 6, indicating which transaction file to access. The command TRANSACTION_COUNT_EX(1) works the same as the command TRANSACTION_COUNT.

Example ...

DataCount_1:

DataCount% = TRANSACTION_COUNT_EX(1) CLS

PRINT DataCount%, "Data in transaction file 1."

RETURN ...

See Also TRANSACTION_COUNT

UPDATE_TRANSACTION

Purpose To update a transaction record in the first (default) transaction file.

Syntax UPDATE_TRANSACTION(N%, data$)

Remarks "N%" is an integer variable, indicating the ordinal number of the transaction record to be updated.

"data$" is a string variable, representing the character string to replace the old data.

Example ...

UpdateTransaction:

UPDATE_TRANSACTION(Num%, NewData$) RETURN

...

See Also GET_TRANSACTION_DATA$, SAVE_TRANSACTION, UPDATE_TRANSACTION_EX

UPDATE_TRANSACTION_EX

Purpose To update a transaction record in a specified transaction file.

Syntax UPDATE_TRANSACTION_EX(file%, N%, data$)

Remarks "file%" is an integer variable in the range of 1 to 6, indicating which transaction file to access. The command UPDATE_TRANSACTION_EX(1, N%, data$) works the same as the command UPDATE_TRANSACTION(N%, data$).

"N%" is an integer variable, indicating the ordinal number of the transaction record to be updated.

"data$" is a string variable, representing the character string to replace the old data.

Example ...

UpdateTransaction_1:

UPDATE_TRANSACTION_EX(1, Num%, NewData$) RETURN

...

See Also GET_TRANSACTION_DATA_EX$, SAVE_TRANSACTION_EX, UPDATE_TRANSACTION

In document msoptbasiccompilerv3.04 (Page 152-158)

Related documents