PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Question on HReadSeekFirst / HFound()
Question on HReadSeekFirst / HFound()
Iniciado por guest, 01,sep. 2017 04:34 - 14 respuestas
Publicado el 01,septiembre 2017 - 04:34
Hello Gang ! Namaste !!
Here are two piece of code :

*****************************************
// Find the first record for which
// the CUSTOMER name is MOORE
HReadSeekFirst(CUSTOMER, NAME, "MOORE")
IF HFound(CUSTOMER) = False THEN
Error("Customer not found")
RETURN
ELSE
// Continue the process on the customer named MOORE
END

*****************************************
IF HReadSeekFirst(CUSTOMER, NAME, "MOORE") = False then
Error("Customer not found")
RETURN
ELSE
// Continue the process on the customer named MOORE
END
**************************************

What is the difference between these two codes ?? Should I call HFound() after HReadSeekFirst / HReadSeekLast ??
Which is Better Practice ??
Thanks!!
Publicado el 01,septiembre 2017 - 08:08
Hi Binod,

I use the second method a lot. It is shorter and it works like it should.
It works imho the same as calling HFound().
Publicado el 01,septiembre 2017 - 08:15
I use first method. Like to have clear code, easy to read. Both situations are correct. You use what ever you prefer .
Publicado el 01,septiembre 2017 - 10:14
Hello,

I think this is shorter and easy to read


IF HReadSeekFirst(CUSTOMER, NAME, "MOORE") then
/ Continue the process on the customer named MOORE
ELSE
Error("Customer not found")
END
Publicado el 01,septiembre 2017 - 11:03
Or even shorter :

IF NOT HReadSeekFirst(CUSTOMER, NAME, "MOORE") then Error("Customer not found") RETURN END // Continue the process on the customer named MOORE
Publicado el 01,septiembre 2017 - 12:25
I think Frans might be the winner in the processing time efficiency stakes, but I agree with ICI, I too use the "easy to read and maintain" syntax. To me saving billionth of a second in processing time in a business processing application is neither "here-nor-there"; maintainability is king! ...although if the READ statement is in a loop might change things, but only slightly ...discuss :xcool:
Publicado el 02,septiembre 2017 - 01:12
If we want to be so precise in mm I use this combination of few codes from there:

I prefer this:

sName is string = "MOORE" (or EDT_Name)
HReadSeekFirst(CUSTOMER, NAME, sName)
IF HFound(CUSTOMER)=False then
Error("Customer not found")
RETURN
END
// Continue the process on the customer named MOORE

I want to read whole process like we talk in real life, how it can be closer.
Publicado el 02,septiembre 2017 - 14:54
My 2 cents,

if hreadseek(F_Customer,asName,"MOORE",hidentical)=false then
//test if DB error and manage or if simply not found
else
//Manage customer moore
end

Be aware that if yo don't use the hidentical option, then you will find MOOREEEEE when looking for MOORE.

Also, I do NOT use hreadseekFIRST if I'm not going to loop on a hreadNEXT afterwards. With hreadseek, I'm not looking for the first of a series, I'm looking for an EXACT match (hence the hidentical option).

Best regards
Publicado el 02,septiembre 2017 - 16:36
I have always followed the maxim that you need to design and code with the thought that the next developer that maintains your code is a homicidal maniac that knows where you live.
Publicado el 03,septiembre 2017 - 00:10
Hello Art,

now, that one, I want to publish as a citation on the front page of my web site :-)

Can I? Can I? Please!Please!Please!

:xcool: :cheers: :D
Publicado el 03,septiembre 2017 - 07:25
ICI,

I agree with you. I also for many years now write code as close to how I can speak it so that it becomes as obvious as possible. I rather write more code and many more comments than try and be a little bit faster in typing or execution. ... thought I was the only one lol! :)
Publicado el 03,septiembre 2017 - 07:44
Hi Art, I agree on that, definitely!
Publicado el 03,septiembre 2017 - 10:59
Hi Fabrice,

I have to disagree on this one. The Help says:
HReadSeekFirst (Function)
Positions on the first record of a data file whose value for a specific item is strictly equal to a sought value (exact-match search). The record is read and the corresponding HFSQL variables are updated.

I have used IF (NOT) HreadSeekFirst for as long as I can remember and never had any problems.
The hIdentical constant is mentioned only for HreadFirst.

Kind regards,
Piet
Publicado el 03,septiembre 2017 - 18:55
Hi Piet, you're right!

However, there is a small but important difference between HReadSeekFirst(...) and the much older HReadSeek(.... [,hidentical]) !

HReadSeekFirst(..) positions on the first record / key within a set of identical keys. Several HReadNext(..) after that are guaranteed to find all of the records containing exactly that key.

HReadSeek(... , hidentical) finds any record within that set of identical keys - not necessarily the really first one of the set - and a few HReadNext(...) after that will NOT find all of the records with the same key, reading just ends whenever a record with a key greater than the sought one appears.

This had been one of my demonstrable problems with HReadSeek(...) in early WINDEV 5.5 programs, the answer to that had been HReadSeekFirst(...)!

It may be, I did not test it, that HReadSeekFirst(...) and HReadSeek(..., hidentical) are working the same way by now.
Publicado el 04,septiembre 2017 - 11:19
Hi Guenter,

Indeed, this stuff is all still there for compatibility reasons.
I don't remember ever using HReadFirst anymore, perhaps in the days there were no client server and queries yet.
I'm only using HReadSeekFirst to find unique identifiers, for the rest I think queries are the better option.

Kind regards,
Piet