Solved

Seek a record in file and updating it

Posted on 2000-02-16
9
215 Views
Last Modified: 2013-12-18
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!
0
Comment
Question by:LotusBlur
  • 6
  • 2
9 Comments
 
LVL 1

Expert Comment

by:rfharris
ID: 2531242
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!
0
 
LVL 1

Expert Comment

by:rfharris
ID: 2531274
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.)
0
 
LVL 2

Expert Comment

by:Paebdb
ID: 2531408
also, as what type of file are you opening it and do you also close it ?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:LotusBlur
ID: 2533928
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

0
 
LVL 1

Expert Comment

by:rfharris
ID: 2534790
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
0
 
LVL 1

Expert Comment

by:rfharris
ID: 2534828
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?
0
 
LVL 1

Accepted Solution

by:
rfharris earned 70 total points
ID: 2534992
The following code is tested as compiled and working.  Note that I was unable to make the "like" comparison work unless padding my search criteria with spaces to equal the length declared for the recStud.name (in my example I set it to length 20).

In the Declarations:
Type PersonRecord
      Number As Integer
      Name As String * 20
End Type

In the Initialize event:
Sub Initialize
      Dim idFile As Integer
      Dim fileName As String
      Dim recStud As PersonRecord
      idFile = Freefile()
      fileName$ = "data.txt"
' First, open a random file with a record length equal to
' the size of the records to be stored.
      Open fileName$ For Random As idFile Len = Len(recStud)
%REM
      For counter=1 To Eof(idFile)
            Get idFile, counter, recStud
            If recStud.Name Like "Jack Jones" Then
                  recStud.Name="Jack Replaced"
                  Put idFile, counter, recStud
            End If          
      Next counter          
%END REM      
      counter = 1
      NameForSearch$ = "Jack Jones"
      SearchString$ = NameForSearch$ + Space(20-Len(NameForSearch$))
      Do Until Eof(idfile)
            Get #idFile, counter, recStud             
            If recStud.Name Like SearchString$ Then
                  recStud.Name="Jack Replaced"
                  Put #idFile, counter, recStud
            End If    
            counter = counter + 1
      Loop            
      Close idFile              ' Close the file.
End Sub

0
 
LVL 1

Expert Comment

by:rfharris
ID: 2535002
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.
0
 

Author Comment

by:LotusBlur
ID: 2540978
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.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question