Link to home
Start Free TrialLog in
Avatar of LotusBlur
LotusBlur

asked on

Seek a record in file and updating it

I have written a program to write to a file and retrieve the records. But currently i'm stuck at this where i need to search a certain record and update it.

Dim idFile As Integer
.
.
For counter=1 To Eof(idFile)
    Get idFile, counter, recStud
    If recStud.Name Like "Jessie" Then
        recStud.Name=200
        Put idFile, counter, recStud
    End If          
Next counter  

I have a problem 'putting' the updated record back or maybe i'm using a wrong way to update records. So, experts out there, pls help. Tq!
Avatar of rfharris
rfharris

Hello -

You may want to run this code with the Lotus debugger so you can watch this code and its results line by line during execution.

Places where I have concern are:
1) your preparation and opening of the text file: was it successful?

2) is your code handling the 'idfile' variable correctly?  (I always use the nomanclature shown in the help files when using external files.  My 'idfile' is declared as:
fileNum% = FreeFile()
and later referenced as:
Put #fileNum%, counter, rec

3) how well did it handle your swap of the recstud.name value from text to numeric?  I'm guessing this line may fail -- try putting the 200 in quotes and treating it as a text value?

I think the nomanclature of the idfile (failing to put the # in front) and  the sudden swap from text to numeric for the recStud.name are causing troubles.  The debugger should be able to help you monitor this code.

Good luck!
More ...

The following snippet is from Notes Designer help on use of the Get and Put statements.  I have pasted the syntax description of the 'fileNumber':

FileNumber
The number assigned to the file when it was opened with the Open statement. **Note that the pound sign (#),  fileNumber, and variableName are all required.**

(Emphasis using the "**" characters added.)
also, as what type of file are you opening it and do you also close it ?
Avatar of LotusBlur

ASKER

Hi rfharris,

I'm pretty sure I managed to write and read from the file. That was the first part I worked on. When I added

   If recStud.Name Like "Jessie" Then
           recStud.Name="John"  (sorry, typo error earlier)
           Put idFile, counter, recStud
   End If          

That's when error occurs. From what u said, do u mean i have to write

Put #idFile%, counter,recStud

instead of idFile, counter, recStud?

I'll try this for now, let's hope it works.

p.s : for Paebdb, i used a random access file. and yes, i did close it.

Thanks

I suggest that both your Get and Put statements use the # prefix when referring to the idfile variable.  

The %, as an explicit declaration of type integer, is optional depending on how you had first declared/used the variable.  If you use the % in your earliest declaration/use of idfile - then continue to use it in every reference -- but do *not* add it only on the Get/Put lines.
  -R
By the way -- what kind of error are you getting?  When does it occur (at save/compile or during code execution)?  Message from the error?
ASKER CERTIFIED SOLUTION
Avatar of rfharris
rfharris

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry - please ignore the code between the %REM and %END REM lines.  I was playing with two methods of advancing through the file and I forgot to remove the method closest to your own before pasting the code.
thanks rfharris... i'll just take it that it works. but now i realised the thing i'm working on might not need to use writing to external file, instead, i may need to have an external database(any .dbf) and connect to Notes using ODBC. so, pls lookout for my next question as i've never done odbc before. thanks again.