VB:- Stupid Logic Question: Anding two values

Started by
8 comments, last by aidan_walsh 21 years, 5 months ago
I really hate to post what must seem like such a basic question, but I really don't understand how this works. In one of my collage tutorials, we were given code that checks if an ADO recordset has an entry using the code If Not (rstStudents.BOF And rstStudents.EOF) Then While it works beautifully, I just don't know how! What effect does ANDing the BOF and EOF entries have? How exactly does this check every record between them? I understand how the NOT changes the result to the inverse, but it's the And that I can't comprehend. Thanks in advance. If at first you don't succeed, call it version 1.0
SketchSoft | SketchNews

[edited by - doodle_sketch on November 5, 2002 11:32:35 AM]
www.aidanwalsh(.net)(.info)
Advertisement
The code you entered only checks to see if the recordset is not at the beginning of the file and not the end of the file. This would mean that it''s currently on a record somewhere between.

borngamer
I don''t think your statement should work like you want. What you''re saying is literaly WHILE it''s NOT bof AND eof THEN
From my understanding of what you want if you take the not out it should return the bof and eof, but because you put the and in there it looks for an instance where your list or file is at the beginning and the end at the same time. Which shouldn''t give you anything... Or I could be completely wrong...
it looks wrong to me too
OK... I seem to have misinterpruted the code as doing something it dosn''t. I think I understand how it works now. Thanks Guys!

If at first you don''t succeed, call it version 1.0

SketchSoft | SketchNews
www.aidanwalsh(.net)(.info)
After you query your database you don''t want to perform any actions on the recordset if you the recordset contains no fields. This if then logic simply makes sure there is at least one field in the recordset. If you query''ed for Lastname = ''Smith'' and no one has last name Smith then there won''t be any fields in the recordset so you don''t want to play with data that isn''t there.
After reading my last post it seemed kind of confusing. With the way you are doing it, it looks for a time when it is NOT at the beginning AND end. which shouldn''t occur since the beginning and end of a file aren''t in the same spot. So your while statement should run through the entire thing, first and last element. But if you changed the AND to an OR it would look to see if it was at either the beginning or end. Not both.
After reading my last post it seemed kind of confusing. With the way you are doing it, it looks for a time when it is NOT at the beginning AND end. which shouldn''t occur since the beginning and end of a file aren''t in the same spot. So your while statement should run through the entire thing, first and last element. But if you changed the AND to an OR it would look to see if it was at either the beginning or end. Not both.
If Not (rstStudents.BOF And rstStudents.EOF) Then

About the only time that would return True is if you're given an empty recordset. You cannot be at the beginning AND at the end at the same time (hence the And), unless there is nothing in between the two, and therefore empty. I believe your tutorial is checking to make sure the recordset has something in it before proceeding.

If Not (rstStudents.BOF Or rstStudents.EOF) Then

If your And was replaced with an Or, then this would return True if you were at any record in between the recordset's start and end points.

Explanation on And (in case you need it):
If (A And B) = True Then
(A And B) will return True only if A = True and B = True.
If either A or B is False, then (A And B) will return False.

Hope that helps.

Edit: Ahh, people are too fast!

[edited by - Tri on November 5, 2002 12:01:06 PM]
OK. I understand how the statement works now, and I think Tri even unwittingly gave me the answer to the next question I have to solve

Thanks again everyone; and great work Tri!!

If at first you don''t succeed, call it version 1.0

SketchSoft | SketchNews
www.aidanwalsh(.net)(.info)

This topic is closed to new replies.

Advertisement