Solved

Seek a record in file and updating it

Posted on 2000-02-16
9
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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