Archived

This topic is now archived and is closed to further replies.

aidan_walsh

VB:- Stupid Logic Question: Anding two values

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites