Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Very Hot Topic (More than 25 Replies) Unbound Field & On Form Change (Read 3131 times)
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Unbound Field & On Form Change
Dec 30th, 2005 at 4:00am
Print Post Print Post  
Hi -

In  Version 1.1.3, according to the Change Log, "Unbound LEs no longer trigger Form changed warnings on closing" and that, indeed, is a blessing.

Are they; however, still creating a "form change" condition?

For example, I have a date of birth and age LE.  The date of birth is bound to a field and the Age LE is not ... it is a calculated LE on form entry (and in a few other instances); however all it does is calculate the age.

The on form entry programming is: 
Code
Select All
If not @isblank(Birthdate) then

     Age = @YEAR(@DATE)-@YEAR(BirthDate) - ((@MONTH(@DATE) < @MONTH(BirthDate))
     or (@MONTH(@DATE) = @MONTH(BirthDate) AND @DOM(@DATE) < @DOM(BirthDate)))
 



(By the way, please ignore - other than if it is relevant to my specific question - the age programming.  The reason I say this is that I have previously been told that it could not work and yet I have never found one single instance when it did not properly calculate the correct age).

(I see no other programmed "change" to the form except for the unbound Age LE (and, similarly an undboud  Years LE, based on an anniversary date)).

Then, in the Last Updated LE on form change I have:
Code
Select All
Last Updated = @date 



Unfortunately, if I am searching through a stack of records I noticed the following problem.

If the Birthdate LE is blank, I can advance to the next form, revert to the previous form and can verify that the Last Updated LE has not changed.

If on the other hand there is a birthdate, then when I advance and revert to the record which contained the birthdate, the last updated field value has been changed to the current date.

What am I overlooking and how can I fix this.  Naturally, I only want the last updated field to be changed when, in fact, I make a change to one or more of the bound LE's.

Thanks!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Unbound Field & On Form Change
Reply #1 - Dec 30th, 2005 at 1:55pm
Print Post Print Post  
Quote:
For example, I have a date of birth and age LE.  The date of birth is bound to a field and the Age LE is not ... it is a calculated LE on form entry (and in a few other instances); however all it does is calculate the age.

The on form entry programming is: 
Code
Select All
If not @isblank(Birthdate) then

     Age = @YEAR(@DATE)-@YEAR(BirthDate) - ((@MONTH(@DATE) < @MONTH(BirthDate))
     or (@MONTH(@DATE) = @MONTH(BirthDate) AND @DOM(@DATE) < @DOM(BirthDate)))
 



(By the way, please ignore - other than if it is relevant to my specific question - the age programming.  The reason I say this is that I have previously been told that it could not work and yet I have never found one single instance when it did not properly calculate the correct age).

I don't want to hiack your thread, but I can't ignore this because it looks like it will be very useful to some things I need to do.  But I'm having a bit of trouble parsing it.  What does the "or" condition look to and do?
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Unbound Field & On Form Change
Reply #2 - Dec 30th, 2005 at 2:19pm
Print Post Print Post  
Spencer,

The Form Change and Element Change events run whenever any value on the form is changed, even if it is unbound. Chaging only unbound elements will no longer trigger the Save warnings (as there is nothing to save), but it will still trigger the programming event. Otherwise, you could not do anything in response to changing an unbound element, such as selecting something from an unbound combo box.

The trick is to put the code in the events to which you actually want to respond. If you don't want the code to run when any element value changes, the code does not belong in the On Form Change event. It belongs in the On Element Change event of only those elements that "count" as far as you are concerned for this particular form.

Alternately, you may want to move the code that  calculates Age somewhere other than On Form Entry so it doesn't run just because you passed through on your way to another record.
  

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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Unbound Field & On Form Change
Reply #3 - Dec 30th, 2005 at 5:22pm
Print Post Print Post  
Erika -

The reason I put the age/years calculation in the on form entry is that I do want to see the correct age even if I am just looking at a form and I don't want to have to remember to click on a "button" (which I could easily put there) to calculate the age.  I sometimes do want to simply scan through a stack of records to check age.  (I also have it on the on the birthdate/anniversary elements exit event, so that it will automatically appear instantly, should I enter a birthdate or anniversary).  In that case I do want the last update field executed but only because I made a change to a bound element.

As for putting last update programming in "on element change" I have about 84 layout elements.  I want the last update field populated for all but nine of the elements (all of which are unbound).

If, as you suggested, I "put the code in the events to which I actually want to respond" I would have to program 75 of the 84 elements.  This is not the worst thing in the world but it is certainly a "one-time" nuicance" for each of my databases (since most of them have a similar situation).

You said: Quote:
Otherwise, you could not do anything in response to changing an unbound element, such as selecting something from an unbound combo box.


So, I have a REQUEST, for program enhancement (unless I am overlooking something).

Why NOT preclude an unboud field from triggering a program event - but ONLY in the "on form change" programming?

In your example of having a combo box respond, I only need it to respond when I click on (or enter) that particular LE ... so I would only need the programming executed on the element entry event.

My other unbound fields are all command buttons that cause programming to be triggered but without affecting any of the bound layout elements on the form (such as looking up a zip-code, retrieving an alternate record, printing an envelope etc.).

I cannot think of a single instance when I would NEED a click on an unbound field to trigger my on form change event programming.

And by the way, until you pointed this out I hadn't realized that there was another problem.  Even if a record does NOT have a birthdate/anniversary to trigger on form change programming, clicking on any one of my command buttons will.

Alternatively, should there be a reason to trigger on form change event programming, then how about a "switch" built into code that would allow the user to enter a programming statement in the on form change event and tell Sesame whether or not to include unbound fields?

Thanks!



  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Unbound Field & On Form Change
Reply #4 - Dec 30th, 2005 at 6:01pm
Print Post Print Post  
Quote:
I cannot think of a single instance when I would NEED a click on an unbound field to trigger my on form change event programming.


I can. And, from the real world apps I see on a daily basis, so can lots of other people.

I'm in the middle of something right now, but I have an idea that might give you what you need. I'll try to get to it later today.
  

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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Unbound Field & On Form Change
Reply #5 - Dec 30th, 2005 at 6:13pm
Print Post Print Post  
CAPTAIN INFINITY -

No need to apologize for "hacking" my code.  If it is something you are able to use, I am delighted.

Code
Select All
If not @isblank(Birthdate) then

     Age = @YEAR(@DATE)-@YEAR(BirthDate) - ((@MONTH(@DATE) < @MONTH(BirthDate))
     or (@MONTH(@DATE) = @MONTH(BirthDate) AND @DOM(@DATE) < @DOM(BirthDate)))
 



To tell you the truth, I obtained this code from Symantec Technical Support (when there was such a thing) for use in Q&A about what - 20 years ago?  lol  ... and it works like a charm in Sesame.

As best I can recall the only time I had a problem with "earlier" code I had created was if it was the same date (day of month) as the birthday.  In other words the age would calculate properly if you checked it either a day before (or earlier) or a day after (or later) than the actual birthdate.  But, if it was on the actual birthdate it would be off by one year.

This programming was designed to fix that.  When it was provided, I understood it perfectly.  Now I only understand it in theory and am not able to disect it without an extraordinary amount of effort.

The way it is written, it incorporates ("unseen" in the code) if/then conditions.

But I do offer you this.  Here's a way to test it.  I just went to my birthdate field - today - December 30, 2005.

If I enter a birthdate of December 31, 2000, the age is shown as 4 (because indeed the person is a day shy of being 5 years old)

If I enter a birthdate of December 30, 2000, the age is shown as 5 (because indeed, today is the day the person reached age 5)

If I enter a birthdate of December 29, 2000, the age is shown as 5 (because indeed the person has passed reaching the age of 5)

So I have checked the date of birth as being (1) a day (or more) before the actual birthdate, (2) on the actual birthdate or (3) a day (or more) after the actual birthdate - and it calculates correctly.  I cannot think of a single "example" that would "slip through" the programming, except that:

I DO NOT know whether this works correctly for someone born on February 29th of a leap year; however, I never had a single instance where I needed to calculate based on February 29 and if needed, it should be easy enough to modify the programming for that particular date.

I know that I did not answer your question precisely but hope that the information I did provide will help you.  

If it does not then please be specific about what you want to do.

I have numerous other (old Q&A) programming statements that do "math" calculations based on a date (of birth, anniversary, fixed date, etc.)

I do hope that this response will help you and wish you good luck.

By the way, just for "accuracy", I do not believe that Q&A had an @isblank function so the "lead in" was probably something like:  If birthdate /=  (not blank)       or      If birthdate <>"" (less than or greater than nothing).  While that might work in Sesame, as well, it is not recommended - so Erika has told me and told me and told me ... lol



  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Unbound Field & On Form Change
Reply #6 - Dec 30th, 2005 at 6:27pm
Print Post Print Post  
Erika -

No rush.  This code has been working incorrectly (meaning it is not doing what I want - I am not saying that is not working as intended) for quite some time now and is certainly not critical).  But, when properly executed, can frequently be of value to me.

Code
Select All
I can. And, from the real world apps I see on a daily basis, so can lots of other people.
 



So, are you implying that MY APPLICATION is NOT a REAL WORLD application.  lol   Just kidding!!!!!

But, in all seriousness, when you do provide your recommendation I would also appreciate your giving me a couple of examples of when you would want programming triggered based on an on form change event limited to a change in an unbound field. 

The only type of situation I can think of would be if I wanted programming to execute based on age.  So, for example, I might have programming that would say "If age => 62 then Senior Citizen Discount = "Yes"  .... BUT, in that type of situation, a change would also occur to a bound element (Senior Citizen Discount).

Knowing what I am overlooking might be very helpful to me in future database design (especially if it is for someone other than myself).

Thanks!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Unbound Field & On Form Change
Reply #7 - Dec 30th, 2005 at 6:42pm
Print Post Print Post  
Quote:
The only type of situation I can think of would be if I wanted programming to execute based on age.  So, for example, I might have programming that would say "If age => 62 then Senior Citizen Discount = "Yes"  .... BUT, in that type of situation, a change would also occur to a bound element (Senior Citizen Discount).


Your example is exactly the type of situation I mean. You want a bound value to change because you altered an unbound value. It is the changing of the unbound value that triggers the On Form Change program which sets the bound value. If the change to Age doesn't trigger the progamming, the Senior Citizen Discount never gets set.
  

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


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Unbound Field & On Form Change
Reply #8 - Dec 30th, 2005 at 7:07pm
Print Post Print Post  
Spencer,

Thank you, your info is helpful and illuminating.  I plan to use your code in my Personnel database, and may tweak it a bit to age Open Receivables.

Still, though...that "OR" floating in there baffles me.  Just what is it comparing?

Thanks again.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Unbound Field & On Form Change
Reply #9 - Dec 30th, 2005 at 7:19pm
Print Post Print Post  
Quote:
I don't want to hiack your thread, but I can't ignore this because it looks like it will be very useful to some things I need to do.  But I'm having a bit of trouble parsing it.  What does the "or" condition look to and do?


Infinity,

The code subtracts the years. It then subtracts 1 if the person has not yet reached their birthday this year or zero if they have. The OR condition is boolean and returns 1 or 0.

I'll show you how it works by resolving the logic step by step. My birthday is Feb 10, 1969. Therefore to find out how old I am:

@YEAR(@DATE)-@YEAR(BirthDate) - ((@MONTH(@DATE) < @MONTH(BirthDate))
     or (@MONTH(@DATE) = @MONTH(BirthDate) AND @DOM(@DATE) < @DOM(BirthDate)))

First, we resolve the date months and years:
2005-1969 - ((12 < 2)  or (12 = 2 AND 30 < 10))

We do the first subtraction to find out how many years:
36 - ((12 < 2)  or (12 = 2 AND 30 < 10))

Now, we resolve the rest of the expressions. They are boolean, so they will all resolve to either 1 (true) or 0 (false):
36 - ((0)  or (0 AND 0))

Resolve the AND. For AND, both must be true. They aren't so:
36 - ((0)  or (0))

Resolve the OR. For OR, if either is true, it's true. Neither is true, so:
36 - 0

Do the math, and I am:
36

-------------------------
Let's do this again, but this time, lets make my birthday Dec 31, 1969. Meaning I have not yet had my birthday.

2005-1969 - ((12 < 12)  or (12 = 12 AND 30 < 31))

36 - ((12 < 12)  or (12 = 12 AND 30 < 31))

36 - ((0)  or (1 AND 1))

36 - ((0)  or (1))

36 - 1

My age is: 35

------------------------

See how it works?

  

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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Unbound Field & On Form Change
Reply #10 - Dec 30th, 2005 at 7:28pm
Print Post Print Post  
CAPTAIN INFINITY -

Code
Select All
If not @isblank(Birthdate) then

    Age = @YEAR(@DATE)-@YEAR(BirthDate) - ((@MONTH(@DATE) < @MONTH(BirthDate))
     or (@MONTH(@DATE) = @MONTH(BirthDate) AND @DOM(@DATE) < @DOM(BirthDate)))   



POW!

I believe that something "tucked away" more than 20 years ago has just resurfaced.

I BELIEVE that I may remember the parsing and that it provides for 4 separate "conditions" the first being the condition of the BirthdateLE and remaining 3 being on the comparison of the Year, Month and Date of birth.   My explanation is based  on my example of calculating the age on December 30, 2005 with a birthdate of either (1) December 31, 2000 or (2) December 30, 2000 or (3) December 29, 2000

1)      The easiest, of course, is "IF NOT @BLANK(BIRTHDATE) (which apparently you understand).   It simply says if the birthdate element contains a value then execute the following programming.  Otherwise (if the field is blank) the programming will be ignored.

2)      The second (and also easy to understand) is "AGE = @YEAR(@DATE) - @YEAR(BIRTHDATE)"  This simply calculates a number of years by taking the current year (2005) and subtracting the year of birth (2000) with a result of "5."  Now the question becomes, "Is this the correct age?"

3)      The next portion " – ((@MONTH(@DATE) < @MONTH (BIRTHDATE" is a combination of an if/then true/false condition.  It is saying to SUBTRACT the response to the true/false "condition" of the months.  IF the month of the actual date is LESS THAN the month of the birthdate THEN subtract the true/false response.  If the condition is TRUE – a "1" will be subtracted.  Since the month of the actual date is DECEMBER and the month of Birth is DECEMBER the condition is FALSE – and so zero (0) is subtracted, leaving the age as 5

4)      And now for the "toughest" part – and the part you want to understand, we have

OR (@MONTH@DATE) = @MONTH(BIRTHDATE) AND @DOM(@DATE < @DOM(BIRTHDATE)))

If the month of the current date is equal to the month of birth (in my example December = December) AND the DATE OF MONTH of the CURRENT DATE date is  LESS THAN the DATE OF MONTH of the BIRTHDATE that would make the condition true (and 1 would be subtracted).  Here's how it plays out

On December 30, 2005  with a birthdate of:

December 29, 2000 – the condition is false and a zero is subtracted leaving age 5
December 30, 2000 – the condition is false and a zero is subtracted leaving age 5
December 31, 2000 – the condition is true and a "1" is subtracted making the age 4

I believe (and hope) that my premise is correct. 

I tried to make this as easy to understand as possible and hope I've succeeded.

Once again, good luck!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Unbound Field & On Form Change
Reply #11 - Dec 30th, 2005 at 7:49pm
Print Post Print Post  
Erika -

AARRRGGHHH!!!!


Why didn't you tell me you were responding to Captain Infinity - you would have saved me all my trouble.  lol 

Now, getting back to my original scenario.

Code
Select All
You want a bound value to change because you altered an unbound value. It is the changing of the unbound value that triggers the On Form Change program which sets the bound value. If the change to Age doesn't trigger the progamming, the Senior Citizen Discount never gets set 



This is the part I don't understand.  The age LE is changing based on FORM ENTRY.  It is not bound to a field and so I onle "see it" in the unboud Age LE.  Again, the age calculation was triggered by the on form entry event.

Now, the SENIOR DISCOUNT is a bound field but if the programming were also on form entry following the age caculation it would seem to me that it would still calculate and since it IS IN a bound field that - in and of itself, without regard to the age calculation would trigger the "on form change event" programming to execute and thus (since the element is bound) save the calculated value, along with my LAST UPDATE LE since there was (in the Senior Discount LE) a form change AND the LAST UPDATE LE is bound. 

I admire your expertise and am certain you must be right - but somehow I am just not getting it from the explanation ... and would like to.

Thanks!

25 1/2 MORE DAYS
  but who's counting?   lol

  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Unbound Field & On Form Change
Reply #12 - Dec 30th, 2005 at 8:10pm
Print Post Print Post  
Wow.  Erika, Spencer...both have you have blown my mind.  I had no idea such complex stuff could be jammed in such a simple statement.  Thank you both for your explanations.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Unbound Field & On Form Change
Reply #13 - Dec 31st, 2005 at 1:27am
Print Post Print Post  
Spencer,

I didn't realize that your example was meant to run On Form Entry. I was talking about typing into or calculating Age, changing the unbound value which would in turn trigger the On Form Change event to set the value in a bound element.

There are many examples of wanting to change a bound value based on a change to an unbound element.

For example, you may have three unbound elements whose values are used a calculate a single bound element. If you change any of the unbound values, the bound value should recalculate. Examples of this include a custom calculator, assembling an adddress, creating a customer code, etc.

You may want to make a selection from an unbound combo box and have the change trigger a recalculation of bound elements on your Form.

You may want to make a choice from an unbound radio button group and have the change trigger a recalculation of bound elements.

And so on...

As to your case, if you don't want certain changes to "count" as a change, set a variable indicating the special condition. It would go something like this:

GLOBAL CODE
[code]stat gFlag as Int

    gFlag = 0[/code]

FORM::ON FORM ENTRY
[code]If Not @IsBlank(Birthdate)
{
     Age = @YEAR(@DATE)-@YEAR(BirthDate) - ((@MONTH(@DATE) < @MONTH(BirthDate)) or (@MONTH(@DATE) = @MONTH(BirthDate) AND @DOM(@DATE) < @DOM(BirthDate)))

    // Set the flag telling SBasic that you
    // don't want this particular change to count.
    gFlag = 1 
}[/code]

FORM::ON FORM CHANGE (or wherever)
[code]// Only set LastUpdate if the change "counts"
If gFlag = 0
{
     LastUpdate = @Date
}
Else
{
    gFlag = 0
}[/code]

This method allows you to manage more than just the limited case of unbound values. You can pick and choose which changes matter based on whatever criteria is appropriate at the moment. Sometimes it will be unbound elements, sometimes it will be only certain values. Sometimes you will want unbound changes to count. Sometimes you won't. Sometimes what you want is the same as what most other people want. Sometimes it isn't.

By using methods like this, you don't have to rely on us as developers to be able to accurately predict what is "right" for each of thousands of users in every circumstance. We try to give you flexible powerful tools that allow you to make these decisions for yourself, as needed.
  

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



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Unbound Field & On Form Change
Reply #14 - Dec 31st, 2005 at 4:32am
Print Post Print Post  
Quote:
I do want to see the correct age even if I am just looking at a form and I don't want to have to remember to click on a "button" (which I could easily put there) to calculate the age.  I sometimes do want to simply scan through a stack of records to check age.

I have been using @Msg to display temporary calculation results. This way, it does not cause a form change condition at all, and doesn't require any special action on your part. Which, I think, was your original concern.

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print