PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Modify a record in Hyper File
Modify a record in Hyper File
Débuté par John Marrone, 21 juin 2004 16:36 - 6 réponses
Posté le 21 juin 2004 - 16:36
Hi
I am trying to modify a record with HModify(). When I do I get an error that I am adding a duplicate record. I am not changing the key field. I just want to change some other fields in the record and update the record with the changes. Here is my code.
HOpenAnalysis("C:\My Projects\DEMO_MDI\DEMO_Test.WDD")
HCreationIfNotFound(DEMO_Testdata)

IF aArr[OL,45] <> "" THEN
HSeek(DEMO_Testdata,RaceID,aArr[OL,45])
// info("Found = " + HFound())
IF HFound() THEN
DEMO_Testdata.Demo_Version = OL + 120
HModify(DEMO_Testdata)
ELSE
DEMO_Testdata.RaceID = aArr[OL,45]
DEMO_Testdata.Demo_Version = OL + 120
HAdd(DEMO_Testdata)
END
Gauge(OL, vnNumOfRec, "Importing " + vcFileName)
END
Can someone please help. I am using the 7.5 demo. I really like this dev tool.
This should be easy. Please help if you can.
Also: I am doing this in code. I am reading in a text file and adding data to the table or sometimes changing data in a record.
Posté le 21 juin 2004 - 17:01
Hallo,
try it with hreadseek and not with hseek.
Christoph
Hi
I am trying to modify a record with HModify(). When I do I get an error that I am adding a duplicate record. I am not changing the key field. I just want to change some other fields in the record and update the record with the changes. Here is my code.
HOpenAnalysis("C:\My Projects\DEMO_MDI\DEMO_Test.WDD")
HCreationIfNotFound(DEMO_Testdata)

IF aArr[OL,45] <> "" THEN
HSeek(DEMO_Testdata,RaceID,aArr[OL,45])
// info("Found = " + HFound())
IF HFound() THEN
DEMO_Testdata.Demo_Version = OL + 120
HModify(DEMO_Testdata)
ELSE
DEMO_Testdata.RaceID = aArr[OL,45]
DEMO_Testdata.Demo_Version = OL + 120
HAdd(DEMO_Testdata)
END
Gauge(OL, vnNumOfRec, "Importing " + vcFileName)
END
Can someone please help. I am using the 7.5 demo. I really like this dev tool.
This should be easy. Please help if you can.
Also: I am doing this in code. I am reading in a text file and adding data to the table or sometimes changing data in a record.
Posté le 21 juin 2004 - 17:32
Chris
Thanks, That worked. But I end up with a blank record. So when I run it again I get the dulpicate error when it tries to modify the blank record??
Hallo,
try it with hreadseek and not with hseek.
Christoph
Hi
I am trying to modify a record with HModify(). When I do I get an error that I am adding a duplicate record. I am not changing the key field. I just want to change some other fields in the record and update the record with the changes. Here is my code.
HOpenAnalysis("C:\My Projects\DEMO_MDI\DEMO_Test.WDD")
HCreationIfNotFound(DEMO_Testdata)

IF aArr[OL,45] <> "" THEN
HSeek(DEMO_Testdata,RaceID,aArr[OL,45])
// info("Found = " + HFound())
IF HFound() THEN
DEMO_Testdata.Demo_Version = OL + 120
HModify(DEMO_Testdata)
ELSE
DEMO_Testdata.RaceID = aArr[OL,45]
DEMO_Testdata.Demo_Version = OL + 120
HAdd(DEMO_Testdata)
END
Gauge(OL, vnNumOfRec, "Importing " + vcFileName)
END
Can someone please help. I am using the 7.5 demo. I really like this dev tool.
This should be easy. Please help if you can.
Also: I am doing this in code. I am reading in a text file and adding data to the table or sometimes changing data in a record.
Posté le 21 juin 2004 - 20:40
Hi Chris
Figured out my problem with the blank record. Thanks again for your help.
John

Hallo,
try it with hreadseek and not with hseek.
Christoph
Hi
I am trying to modify a record with HModify(). When I do I get an error that I am adding a duplicate record. I am not changing the key field. I just want to change some other fields in the record and update the record with the changes. Here is my code.
HOpenAnalysis("C:\My Projects\DEMO_MDI\DEMO_Test.WDD")
HCreationIfNotFound(DEMO_Testdata)

IF aArr[OL,45] <> "" THEN
HSeek(DEMO_Testdata,RaceID,aArr[OL,45])
// info("Found = " + HFound())
IF HFound() THEN
DEMO_Testdata.Demo_Version = OL + 120
HModify(DEMO_Testdata)
ELSE
DEMO_Testdata.RaceID = aArr[OL,45]
DEMO_Testdata.Demo_Version = OL + 120
HAdd(DEMO_Testdata)
END
Gauge(OL, vnNumOfRec, "Importing " + vcFileName)
END
Can someone please help. I am using the 7.5 demo. I really like this dev tool.
This should be easy. Please help if you can.
Also: I am doing this in code. I am reading in a text file and adding data to the table or sometimes changing data in a record.
Posté le 21 juin 2004 - 22:40
Hi
I am trying to modify a record with HModify().


Is the "RaceID" a declared key in the analysis? Is it a unique key with no duplicates?
I noticed the //info("..."). Obvious dead give away of a Clarion user that uses MESSAGE('...') because the debugger is difficult to use. Not the case with WinDev. Remember how easy it was to use the CPD 2.1 debugger? I suggest you read up on the WD debugger and set some STOPs and check the values you are passing, and not just hFound. Here is why...
Things are done a little different in WD than Clarion because of the greater options built into WD.
hSeek(FileName,KeyName,Value) sets a pointer to the file, like the Clarion:
FieldInKey = Value
SET(FileKeyName,FileKeyName)
hReadSeek(FileName,KeyName,Value) sets a pointer and reads the next record, like Clarions:
FieldInKey = Value
SET(FileKeyName,FileKeyName)
NEXT(FileName)
hFound is much like checking ERRORCODE() except more powerful. ERRORCODE() will advise you of file access error (37, 5, etc), while hFound will tell you is if the correct record was found (in addition to file errors) but based upon your original command...
Your command, hReadSeek, just reads the first record based upon your Value (you are SETing and reading). It does not guarantee you have read the record you really wanted to find (Value). Therefore, hFound will tell you (based on your original command) that you have found a record.
Much like Clarion, once you do the NEXT(FileName) you may not have what you think you have. In Clarion the next lines would be:
IF ERRORCODE() then DoWhateverYouDoWithErrors. //this is hFound
IF FIL:FieldInKey = Value
..Change And PUT a record
ELSE
..ADD a record
END
I don't see this same Value check in your WD code, just hFound. If there is ANY record in the Hyperfile and its not the last, with hReadSeek hFound will return TRUE, just like Clarion will not post any ERRORCODE() when a record (even the "wrong" one) is found.
If you use hReadSeek, you will either
a) do it the hard way and write the code for checking the value of the record found, like Clarion, or
b) use the hIdentical option in your command.
(btw,
As always there is an easier way. Use hReadSeekFirst.
hReadSeekFirst(FileName,KeyName,Value) is basically the same as:
FieldInKey = Value
GET(FileName,KeyName)
hReadSeekFirst will perform an identical search. If the exact record you want with the Value you want is NOT found, do the ELSE logic.
IF aArr[OL,45] <> "" THEN
..IF hReadSeekFirst(DEMO_Testdata,RaceID,aArr[OL,45]) THEN
....DEMO_Testdata.Demo_Version = OL + 120
....HModify(DEMO_Testdata)
..ELSE
....DEMO_Testdata.RaceID = aArr[OL,45]
....DEMO_Testdata.Demo_Version = OL + 120
....HAdd(DEMO_Testdata)
..END
..Gauge(OL, vnNumOfRec, "Importing " + vcFileName)
END
Notice I did not use hFound. The function call returned a value.
Get back to us if it doesn't work.
Art Bonds


WinDevUS Website
Posté le 21 juin 2004 - 22:43
Hi Chris
Figured out my problem with the blank record. Thanks again for your help.
John

Ah, read the original post, started and finished a reply, then notice you'd posted this reply some where in between my start and finish.
What was the solution?
Art
Posté le 22 juin 2004 - 13:35
Hi
I am trying to modify a record with HModify().

Is the "RaceID" a declared key in the analysis? Is it a unique key with no duplicates?
I noticed the //info("..."). Obvious dead give away of a Clarion user that uses MESSAGE('...') because the debugger is difficult to use. Not the case with WinDev. Remember how easy it was to use the CPD 2.1 debugger? I suggest you read up on the WD debugger and set some STOPs and check the values you are passing, and not just hFound. Here is why...
Things are done a little different in WD than Clarion because of the greater options built into WD.
hSeek(FileName,KeyName,Value) sets a pointer to the file, like the Clarion:
FieldInKey = Value
SET(FileKeyName,FileKeyName)
hReadSeek(FileName,KeyName,Value) sets a pointer and reads the next record, like Clarions:
FieldInKey = Value
SET(FileKeyName,FileKeyName)
NEXT(FileName)
hFound is much like checking ERRORCODE() except more powerful. ERRORCODE() will advise you of file access error (37, 5, etc), while hFound will tell you is if the correct record was found (in addition to file errors) but based upon your original command...
Your command, hReadSeek, just reads the first record based upon your Value (you are SETing and reading). It does not guarantee you have read the record you really wanted to find (Value). Therefore, hFound will tell you (based on your original command) that you have found a record.
Much like Clarion, once you do the NEXT(FileName) you may not have what you think you have. In Clarion the next lines would be:
IF ERRORCODE() then DoWhateverYouDoWithErrors. //this is hFound
IF FIL:FieldInKey = Value
..Change And PUT a record
ELSE
..ADD a record
END
I don't see this same Value check in your WD code, just hFound. If there is ANY record in the Hyperfile and its not the last, with hReadSeek hFound will return TRUE, just like Clarion will not post any ERRORCODE() when a record (even the "wrong" one) is found.
If you use hReadSeek, you will either
a) do it the hard way and write the code for checking the value of the record found, like Clarion, or
b) use the hIdentical option in your command.
(btw,
As always there is an easier way. Use hReadSeekFirst.
hReadSeekFirst(FileName,KeyName,Value) is basically the same as:
FieldInKey = Value
GET(FileName,KeyName)
hReadSeekFirst will perform an identical search. If the exact record you want with the Value you want is NOT found, do the ELSE logic.
IF aArr[OL,45] <> "" THEN
..IF hReadSeekFirst(DEMO_Testdata,RaceID,aArr[OL,45]) THEN
....DEMO_Testdata.Demo_Version = OL + 120
....HModify(DEMO_Testdata)
..ELSE
....DEMO_Testdata.RaceID = aArr[OL,45]
....DEMO_Testdata.Demo_Version = OL + 120
....HAdd(DEMO_Testdata)
..END
..Gauge(OL, vnNumOfRec, "Importing " + vcFileName)
END
Notice I did not use hFound. The function call returned a value.
Get back to us if it doesn't work.
Art Bonds


Art
Thanks so much for the effort you put into this. This is above and beyond the call of being helpful. It really helped me to understand how to seek a record correctly. I want to thank eveybody. This has laid to rest my concerns of if I need help could I get it with WinDev.
Thanks Again
John Marrone