Normal Topic Custom Nav buttons do not run On Form Exit code (Read 1344 times)
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Custom Nav buttons do not run On Form Exit code
Oct 27th, 2007 at 2:45am
Print Post Print Post  
Solution: Events like On Form Exit cannot run if you are inside custom button code. If you have custom navigation buttons that change which record you are on, those buttons should also perform any tasks normally handled On Form Exit.

I have been fighting an "intermittent" problem for too long!  But I think I may have located the culprit.

I have code in FormName/OnFormExit that does some Audit logging.  Typical lines are like this
Record = @TN(@XLR(........LastRecord +1 stuff
DateEntered = @Date
TimeEntered = @Time
AddedBy = @UserID

But I have run into instances when the code no longer worked.  Double checked, triple checked syntax etc.
Commented out lines, used WriteLn to track process, etc.  And suddenly it works again, for no reason.  Initially I thought it was just an XLR problem, but then realized that none of the code was working.

Well, there's always a reason, and I think I stumbled across the problem tonight.  I need to do more testing, but this is what I found.

If the first line of the programming section is blank, then the code does not run at all.
If I remove the first blank line, then the code runs.
I was able to fix this problem on two forms in an application by removing the blank liine.

The actual format of the programming section was a blank line, followed by a \\commented line, followed by code, like this:
Code
Select All
//  Commented line is here, followed by code.  The line above is BLANK
Record = @TN(@XLR(........LastRecord +1 stuff
DateEntered = @Date
TimeEntered = @Time
.....
....
more code
.....
.......
 



I would like to know if anyonel elcs can duplicate this.  Using version 2.0.3, and this code is in FormName/OnFormExit section.  Don't know yet if it is limited to this one section, or just in this application.  I know that it can be duplicated in other databases within this same application.

Also of possible importance, is that this code may have been a result of XML import.  Don't think that should make a difference, but need to find out.
« Last Edit: Oct 27th, 2007 at 6:02pm by Hammer »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Blank line at top kills code
Reply #1 - Oct 27th, 2007 at 5:32am
Print Post Print Post  
Are you using command buttons for navigation?

I have found that the On Form Exit event does not execute when SelectTreeItem is used to call F10 or Ctrl-F10 (and F9 or Ctrl-F9). I've already written it up and reported it.

Using F10 on the keyboard will allow the code to work properly, but from a command button via SelectTreeItem, it will NOT execute the On Form Exit event at all.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
RE: On Form Exit code fails
Reply #2 - Oct 27th, 2007 at 4:31pm
Print Post Print Post  
Aaargh.... will have to try different combinations.

Yes, I have navigation buttons, but don't recall whether I was using F9/F10 and/or nav icons at top or nav buttons I put on the form.  I will have to try all three versions with/without the blank line.  Based on you input, I suspect the blank line may have been coincidence, because I was looking so hard for the culprit.

There is a well hidden page for known problems and work arounds at http://www.lantica.com/Support/sesame_workarounds.html  But this has had no additions since 1.1.4.

I think it would be good to  have a section on the forum that contains known issues.  It would be right here, easy to find, and Read Only so only modified by Admiin.  This problem has cost me many hours of lost time.  This is the first I have heard about the F10 with navigation buttons issue.  And I am here every day, how those infrequent users?  

Thanks for the info Carl.
« Last Edit: Oct 27th, 2007 at 5:36pm by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Blank line at top kills code
Reply #3 - Oct 27th, 2007 at 5:06pm
Print Post Print Post  
Bob_Hansen wrote on Oct 27th, 2007 at 4:31pm:
This is the first I have heard about the F10 with navigation buttons issue.  And I am here every day, how those infrequent users?

I'm surprised you hadn't seen this before, Bob. It comes up every now and again. We don't put it on the workarounds page as that is really for temporary workarounds to bugs that we intend to fix or very obscure issues. The workarounds are generally obsoleted as soon as a new release comes out.

This actually came up again just a few weeks ago:
http://www.lantica.com/Forum3/cgi-bin/yabb2/YaBB.pl?num=1191093991/1#1

BTW, we tried the blank line situation you describe and can't get it to fail.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: On Form Exit code fails
Reply #4 - Oct 27th, 2007 at 5:34pm
Print Post Print Post  
I can't get it to fail either!  I just got back here to change the title of the thread.  Don't want to mislead anyone.

It is obvious that I was using the buttons when it failed and the icons or F10 when it did not.
I just completed some tests using the four buillt in Navigation icons, F9, F10, and the four buttons that I added to the form.  All the built ins worked, but none of my buttons (one of them uses a macro).

This explains the "intermittent" nature of the problem.  Three ways to save a record and two out of three work.  And since the keyboard is easier to use, then the failure mode is probably used less frequently.

And yes, I also am stunned that I don't recall seeing this before.  Ray and I have been working on an intermittent "XLR" problem for days with no solution.  But this is obviously the cause.  I am sure he will be glad to be reminded about this also.

How about the solution?  Will this be in 2.0.4, or do I need to remove the Navigation buttons?  I suppose I could make a SuRoutine from the OnFormExit code, and call the SubRoutine in each of my navigation buttons.  That sounds like it may work.

Re the workaround comments.
1.  I still think that known problems should be listed here as a separate topic on the forum, especially if they don't have a work around.  If not listed here then perhaps a "sticky" with a link to that page.  The sticky item could be updated whenever there is a change to the workarounds page.

2.  I think items like this should be listed even if there is no work around.  There is a work around when you know about the problem.  The work around is "Don't Do This".

Thanks for listening.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: On Form Exit code fails
Reply #5 - Oct 27th, 2007 at 5:49pm
Print Post Print Post  
Great minds think alike.

I just checked out the earlier posting that you referenced.  I see that you also suggested making a Sub Routine to execute this code.  Great idea!  I totally missed the content in the thread that said it was because it was a button operation.  Duhhh.

I am still hoping that this will be corrected.  As it stands now, we have a situation where we can program command buttons to use all Menu Tree items except a few that are on an exception list.  And that exception list and conditions are not noted anywhere.

And now I have concerns about existing applications with programmed navigation buttons that are not working properly.  This explains some intermittent problems.  Thankfully most users have been using F10/F9
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: On Form Exit code fails
Reply #6 - Oct 27th, 2007 at 5:54pm
Print Post Print Post  
Bob_Hansen wrote on Oct 27th, 2007 at 5:34pm:
How about the solution?  Will this be in 2.0.4, or do I need to remove the Navigation buttons?  I suppose I could make a SuRoutine from the OnFormExit code, and call the SubRoutine in each of my navigation buttons.  That sounds like it may work.


Yes, what you describe is what you need to do, as has been detailed in the link I gave you.

This is not a bug that needs to be fixed. It is a behavior of the program. If you take over Sesame's functions using your own command buttons, you need to take over everything that function does, not just part of it. The solution is to perform whatever code tasks need to be performed before leaving the record as part of your navigation button code.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Custom Nav buttons do not run On Form Exit cod
Reply #7 - Oct 27th, 2007 at 6:26pm
Print Post Print Post  
Quote:
This is not a bug that needs to be fixed. It is a behavior of the program. If you take over Sesame's functions using your own command buttons, you need to take over everything that function does, not just part of it. The solution is to perform whatever code tasks need to be performed before leaving the record as part of your navigation button code.


We need to take over everything?  This is getting scary Erika.
Are you saying that if fields are set up with restrictions in the elements, that I also need to write code to validate the values in those fields?  Isn't that something else that Sesame does when it saves a record.

I don't think that using a command button is trying to replace a Sesame function.  It is enabling us to press a lot of MenuTree commands vs. typing them.  They should be performing the same way as if they had been selected from the Menu Tree.  Doesn't the OnFormEnter code work when records are advanced with buttons?

The code I have been using is a modification of Employee form, Next Record button in First Look application.  Here is the program code, comments are from Lantica:
Quote:
/*
This element is a command button.
This program runs when the button is clicked.
It moves to the next record by telling Sesame
to do what it would do if the user had clicked the
Sesame menu tree item or pressed F10.

If Updating, this will save the current record and move
to the next record. If Adding records, and this is the
last record, this will save the current record
and move to a new record.
*/

var vNav as Int

     If (@ResultSetCurrentPosition() < @ResultSetTotal()) And @Update Then
     {
           vNav = @SelectTreeItem("Search Update Menu!Navigation!Advance Record (F10)")
     }
     Else If @Update Then
     {
           @Msg("There are No More Records In This Set")
     }
     Else If @Add Then
     {
           vNav = @SelectTreeItem("Add Data Menu!Navigation!Advance Record (F10)")
     }


Of particular note is:  telling Sesame to do what it would do if the user had clicked the Sesame menu tree item or pressed F10.  that mirrors my comments above.  We have no way of knowing everything that any Menu Tree item does.  I am not trying to replace the Menu Tree option, I am only trying to use it from a button vs. clicking it on a tree.

I am now screaming, so I better calm down.  I think that you need to rethink this and admit that this is not behaving properly and should be corrected.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Custom Nav buttons do not run On Form Exit cod
Reply #8 - Oct 27th, 2007 at 7:01pm
Print Post Print Post  
Bob_Hansen wrote on Oct 27th, 2007 at 6:26pm:
Are you saying that if fields are set up with restrictions in the elements, that I also need to write code to validate the values in those fields?  Isn't that something else that Sesame does when it saves a record.

It doesn't check restrictions in SBasic, therefore there is no deferral, although the restriction behavior may interfere with your ability to force SBasic to move to a different record when the restrictions say the record cannot be saved.

Quote:
Doesn't the OnFormEnter code work when records are advanced with buttons?

By the time On Form Enter is triggered, your command button code has usually completed and the event is able to run.

Quote:
Of particular note is:  telling Sesame to do what it would do if the user had clicked the Sesame menu tree item or pressed F10.  that mirrors my comments above.  We have no way of knowing everything that any Menu Tree item does.  I am not trying to replace the Menu Tree option, I am only trying to use it from a button vs. clicking it on a tree.

It does behave the same way. The difference is that the menu tree is not running inside an SBasic event. Your command button is. This is only a factor if additional twists are thrown in, such as the presence of On Form Exit event code, which many people do not have.

Quote:
I am now screaming, so I better calm down.

I'm sorry that we can't discuss this without such an emotional reaction. The behavior is consistent if you keep in mind that SBasic is not reentrant. If code is triggered while other code is running, it will be deferred until the prior code finishes. If you are no longer on the same record when the deferred code gets to its turn, it does not run to make sure we do not change values on the wrong record. Making a command button that moves to a different record when there is also On Form Exit code is one of many ways to create this condition.  Again, I'm mainly surprised by your vehemence because this behavior and the methods for dealing with it have been around since an early version of 1.x. These days, when we remind people about this one, they generally shrug and say "Oh, yeah."

In general, if you are going to leave a record in code, and you know that you have conditions where you don't want to leave the record, it's a good idea to check those conditions before instructing Sesame to leave the record.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Blank line at top kills code
Reply #9 - Oct 27th, 2007 at 8:29pm
Print Post Print Post  
Quote:
Are you using command buttons for navigation?

I have found that the On Form Exit event does not execute when SelectTreeItem is used to call F10 or Ctrl-F10 (and F9 or Ctrl-F9). I've already written it up and reported it.

Using F10 on the keyboard will allow the code to work properly, but from a command button via SelectTreeItem, it will NOT execute the On Form Exit event at all.

Bob,

I had a personal revelation on this issue today. I was thinking that this was a bug that needed fixing, but I did a little research and found that Erika is correct!

Sesame cannot allow the On Form Exit event to take place after a command button has caused the record to advance, and On Form Exit cannot execute while the command button event is still running. So, if a command button event moves you to another record, and the On Exit Event is then allowed to execute when it's done, it would be executing on the newly displayed record -- not on the one you wanted it to. This is why On Form Exit code must not be allowed to run when you use SelectTreeItem to "press" F10 from within another event.

The simple solution, as Erika pointed out, is to gather the same code that you have in On Form Exit, and put it into a subroutine. Then, call that subroutine just before the SelectTreeItem that "presses" F10.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged