Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BOF() EOF() error 1

Status
Not open for further replies.

ictoo

Programmer
Sep 3, 2009
33
GB
Hey so my problem might be really simple or im just going about it all wrong.

So im coding a program that views information from a table, i have code that searchs for a record in the table and then displays the value, but if it cant find that record it will add it in the the table.

Now im, having trouble with the very first time it trys to look for the record it cant find it as its not in the table so i get BOF() error but in the code when it get to BOF() i tell it to add a record for the file its looking for.

So what im trying to ask is there a way to supprese this error? so it doesnt try to go to debugger.

Fild and BOF code -

SET REPROCESS to -1

SELECT "epamonitor23"
GO BOTTOM
findfile1 = "PLC20.P2_5_BF1_HOURS_FLAG_X_1"

DO WHILE ALLTRIM(tagname) != findfile1
SKIP -1

IF BOF()
MESSAGEBOX("ADDED")
INSERT INTO epamonitor2;
(tag,;
stamp,;
value1,;
value2,;
count1,;
count2,;
tagname,;
type,;
taggroup);
VALUES ;
(10,;
DATETIME(),;
1,;
0,;
-1,;
-1,;
("PLC20.P2_5_BF1_HOURS_FLAG_X_1"),;
0,;
("EPA_Dlog"));

ENDIF

ENDDO

SET REPROCESS to 1
 
Instead of doing a loop why an sql Statement like this:
Code:
lcTagname =  "PLC20.P2_5_BF1_HOURS_FLAG_X_1"
SELECT * from epamonitor23 where tagname = lcTagName into cursor tmp
If _tally = 0 && Not found
  ** Append the record
else
  ** It found it
endif



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
You could test for BOF() before skipping back one - which will naturally error if your table is empty and you skip backwards before the beginning...

Also, please post your code inside the CODE /CODE tags - it makes it much easier to read.

Code:
SET REPROCESS to -1
SELECT "epamonitor23"
GO BOTTOM 
findfile1 = "PLC20.P2_5_BF1_HOURS_FLAG_X_1"
DO WHILE ALLTRIM(tagname) != findfile1    
	IF !BOF()
		SKIP -1  
	ENDIF      
	IF BOF()        
		MESSAGEBOX("ADDED")
		INSERT INTO epamonitor2;
		    (tag,;
		    stamp,;
		    value1,;
		    value2,;    
		    count1,;    
		    count2,;    
		    tagname,;    
		    type,;    
		    taggroup); 
		    VALUES ;    
		    (10,;    
		    DATETIME(),;    
		    1,;    
		    0,;    
		    -1,;    
		    -1,;    
		    ("PLC20.P2_5_BF1_HOURS_FLAG_X_1"),;    
		    0,;    
		    ("EPA_Dlog"))

	ENDIF
ENDDO
SET REPROCESS to 1

Also, watch for the extra semi-colon on the end of your insert statement (removed above).

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Ictoo,

Griff is right. The short answer is that you need to test for BOF() before you do the SKIP -1. This is not the same as EOF(), where you do the SKIP first and then the test. (I know it's quirky, but there was once a good reason for it.)

However, it seems that you are going about the whole thing in a somewhat long-winded way. If I've understood your code right, you are searching backward through the file. If you hit the start of the file, that's your signal that the record is not found.

Do you have some special reason to do it that way? If not, why not simply do something like this:

Code:
SELECT epamonitor23 && you don't need the quotes, by the way
findfile1 = "PLC20.P2_5_BF1_HOURS_FLAG_X_1"
LOCATE FOR ALLTRIM(tagname) = findfile1
IF NOT FOUND()
  * Insert your new record here
ENDIF

If I've misunderstood what you are trying to achieve, my apologies.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Well im doing it this way as it’s leftover from code im using to locate last record and then displaying a value associated with it, so it’s always showing the latest value of say the temperature of something.

When i look for the latest occurrence for that record i go bottom and then display it, but this is just the first way i found that worked the way i wanted, but for this which is just checking if a value has been reached and inserts an alarm in to the table i think i can use what you have showed me as its just for when it can find the file in the database, i then have some code that checks the dates and adds the record in the table again if the dates don’t match up.

But the table consists of thousands of records, and there will be more than one occurrence of this record as time goes on.

And thanks for pointing out the semi-colon i did have some trouble with the ENDIF and i couldn’t see why.
 
Searching by looking at each record, whether you start from the top or the bottom, is not a good idea. You should add some indexes to your table and use them to allow you to SEEK for the record that you want. It'll be much faster and much more readable code.

VFP rarely requires you to do things by brute force.

Tamar
 
While SEEK or SQL are much better solution, your original fault simply is, that you SKIP -1 before testing BOF(), that must fail, if there is no record at all or no record matching the active FILTER condition. Doesn't make sense to suppress the error, if you can simply turn your logic around and check BOF() before each SKIP -1.

Besides that an easy way to suppress each error is ON ERROR *, which won't give any feedback about errors but might get you in hells kitchen, if you ignore errors that lead to ZAP or DELETE in the wrong workareas. Pre VFP8 you can also do ON ERROR lnError = ERROR() with the same unrecommendation, but this may help in places you expect a certain error that you then can react to. But since VFP8 better use TRY...CATCH logic.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top