In the course of Student Management, BOF and eof are used multiple times to make the logic of the article more clear. At the beginning, it was not very well understood and a little biased, with the exchange and Study of everyone, I gradually increased my understanding of it. Next, let's learn together!
Explanation:
The ADO recordset object is used to hold a record set from a database table. A recordset object consists of records and columns (fields.
In ADO, this object is the most important and most commonly used object for operations on database data.
Bof (before of file) indicates that the current record is located before the first record of the recordset object.
Private sub previuscommand_click () on error goto p_err 'error statement MRC. moveprevious if MRC. bof then' if the current record is in the first record, it moves to the last record MRC. movelast end if call viewdatap_exit: Exit subp_err: msgbox "no record! ", Vbokonly + vbcritical," warning "'The Goto p_exitend sub cannot be completed properly
EOF (end of file) indicates that the current record is located after the last record of the recordset object.
Private sub deletecommand_click () on error goto p_err mybookmark = MRC. bookmark' mark str2 $ = msgbox ("Do you want to delete the current record? ", Vbokcancel," delete current record ") if str2 $ = vbok then 'first, test whether the record to be deleted is the last record MRC. movenext 'if it is the last, first move the current record to the first if MRC. EOF then MRC. movefirst: Move the bookmarks to the first mybookmarl = MRC. bookmark MRC. movelast then moves to the final MRC. delete 'delete MRC. bookmark = mybookmark' find the previously bookmarked call viewdata else mybookmark = MRC. bookmark' flag if not the last MRC. moveprevious 'indicates the next one, because it will be moved to the next MRC after deletion. delete 'delete MRC. bookmark = mybookmark' call viewd ATA end if 'display record else MRC. bookmark = mybookmark' unmark call viewdata end ifp_exit: Exit subp_err: txtname. TEXT = "" txtborndate. TEXT = "" txtsid. TEXT = "" txtrudate. TEXT = "" txttel. TEXT = "" txtaddress. TEXT = "" txtcomment. TEXT = "" msgbox "no record! ", Vbokonly + vbcritical," warning "'The Goto p_exitend sub cannot be completed properly
Return Value: Boolean value is returned for the BOF and EOF attributes.
The BOF and EOF attributes can be used to determine whether the recordset object contains records, or whether the restriction on the recordset object is exceeded when the recordset object is moved from one record to another.
We will discuss the learning in several situations:
1: if the current record is located before the first record, the BOF attribute returns true (-1). If the current record is the first record or is located, false (0) is returned ).
2: If the current record is located in the last record of the recordset object, the EOF attribute returns true, and the current record is the last record of the recordset object or is located before it, false is returned.
3: If the BOF or EOF attribute is true, no current record exists.
4: If no recordset object is opened, the BOF and EOF attributes are set to true, while the recordset object's recordcount attribute is set to zero. When you open a recordset object that contains at least one record, the first record is the current record, and the BOF and EOF attributes are false.
5: if you delete the last record in the recordset object, the BOF and EOF attributes remain false until the current record is rescheduled.
The following table describes the moving methods allowed by the combination of BOF and EOF attributes.
|
Movefirst,
Movelast |
Moveprevious,
Move <0 |
Move 0 |
Movenext,
Move> 0 |
Bof = true,
EOF = false |
Allow |
Error |
Error |
Allow |
Bof = false,
EOF = true |
Allow |
Allow |
Error |
Error |
| True at the same time |
Error |
Error |
Error |
Error |
| False at the same time |
Allow |
Allow |
Allow |
Allow |
The use of the move method does not guarantee that the method is successfully located, but does not produce errors when the specified move method is called.
The following table describes how BOF and EOF attribute settings occur when various move methods are called but records are not successfully located.
|
BOF |
EOF |
| Movefirst, movelast |
Set to true |
Set to true |
| Move 0 |
No changes |
No changes |
| Moveprevious, move <0 |
Set to true |
No changes |
| Movenext, move> 0 |
No changes |
Set to true |