Source language: Translate to:

NB dbfplugin adds new record

Questions about NeoBook PlugIns

Moderator: Neosoft Support

NB dbfplugin adds new record

Postby datadon » Tue Jul 18, 2006 2:38 pm

I have a database that when I open it in a rectangle and scrolled down, it creates a new record. I am not using the add record, but rather just this code as a subroutine that is called each time the database record is changed.

:CBID
Setvar "[CBID.CBID]" "[CBID.SYS][CBID.CONDR]C[CBID.SIZE][CBID.MATL][CBID.SEQNO]"
dbfShowTable "[PubDir]CBID.dbf" "Rectangle8" ""
Return


I am sure the setvar is what is doing the record creating as a C shows up in the [CBID.CBID] field. The rest of the variables are emply.

Is this the way it should work? I don't think using the Setvar should automatically create a new record.

I need the code to work on existing records but not new ones created by browsing the database. Bug or ?

Any help appreciated.
Don

'If you want to get a brontosaurus from 'a' to 'b' then you ride the dinosaur - you don't carry it!'
User avatar
datadon
 
Posts: 389
Joined: Sun Apr 03, 2005 7:55 pm
Location: Lorena Texas

Postby Gaev » Tue Jul 18, 2006 3:33 pm

Don:

From the Help file ...

subroutine (optional)

The name of a subroutine from your publication's Subroutine Action. The subroutine specified here will be automatically executed whenever the database is updated or the current record number changes. This can be useful if you want to activity to take place whenever the reader displays a different record. Subroutines are entered from the Actions page of NeoBook's Book Properties screen.


... so it is unwise to use these commands inside such a routine ... because when the user navigates down the dbf Table, this routine will cause a record (either the one he is navigating to/from) to be updated ... which in turn will cause the routine to be invoked ... which will cause the next update ... and on and on.

I can't say why a new record is being created ... you might look carefully at the rectangle hosting the dbf Table ... when you try to scroll down past the last record, is a new record automatically created ?
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby datadon » Tue Jul 18, 2006 3:46 pm

The subroutine works fine what I need it to do. It is concantonating (spelling?) a number of fields into an ID number and placing it in it's own field. That is ok.

The problem is like you mentioned at the bottom. When I scroll down past the last record, it starts creating new blank records except they all have a C in them which tells me it is reading the subroutine and adding a new record. I don't think it should work that way, but...

We'll see if the author (Dave) has any insight on this.
Don

'If you want to get a brontosaurus from 'a' to 'b' then you ride the dinosaur - you don't carry it!'
User avatar
datadon
 
Posts: 389
Joined: Sun Apr 03, 2005 7:55 pm
Location: Lorena Texas

Postby Neosoft Support » Tue Jul 18, 2006 4:06 pm

I think Gaev is correct, you probably shouldn't modify any of the database's field variables from within the subroutine. Try commenting out this code and see if the problem goes away.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5605
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby datadon » Wed Jul 19, 2006 9:09 am

I'm not sure why you are saying I shouldn't modify any of the fields with the subroutine. If I wanted to have a field calculated based on other field data why shouldn't I do that? Isn't that part of what it is for?

I have found another way to do what I wanted. So I have removed this from the record change routine.

However, here is what I found when I commented out the lines. It was not the setvar action that was causing the new lines, it was the:

dbfShowTable "[PubDir]RWID.dbf" "Rectangle1" ""

What do you think of that?
Last edited by datadon on Wed Jul 19, 2006 1:02 pm, edited 1 time in total.
Don

'If you want to get a brontosaurus from 'a' to 'b' then you ride the dinosaur - you don't carry it!'
User avatar
datadon
 
Posts: 389
Joined: Sun Apr 03, 2005 7:55 pm
Location: Lorena Texas

Postby Neosoft Support » Wed Jul 19, 2006 12:04 pm

The database subroutine is executed whenever the you navigate to a different record, which happens quite often. Typically, the subroutine is used to process simple commands that don't take much time, and can be executed hundreds or thousands of times without slowing down the system or causing problems. Updating a variable used to display the current record number is an example of something that can be done safely within the update subroutine.

On second glance, I don't think your SetVar code should cause any problems. However, executing dbfShowTable from the subroutine is a definite no-no! You only want to execute this action once, not hundreds of times. Also, dbfShowTable can trigger another call to the update subroutine, which may result in your publication getting stuck in an endless loop.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5605
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby datadon » Wed Jul 19, 2006 1:18 pm

Interesting thoughts. My thoughts of updating the records (joining fields into one field) during a browse was definetly not a good idea. I can do that upon creating the record. I lost my head, but again as usual I 'm learning something from it.

I often populate one database with infomation extracted from another database based on queries etc. I often like to have things recalculated when I do that so I just loop though the database. One after the other with the recalc as part of the subroutine for each record change.

What would be the better way to do it?

Thanks again
Don

'If you want to get a brontosaurus from 'a' to 'b' then you ride the dinosaur - you don't carry it!'
User avatar
datadon
 
Posts: 389
Joined: Sun Apr 03, 2005 7:55 pm
Location: Lorena Texas


Return to PlugIn Discussions

Who is online

Users browsing this forum: No registered users and 1 guest