Hot Topic (More than 10 Replies) On Form Change Programming (Read 4430 times)
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
On Form Change Programming
Mar 4th, 2005 at 6:37pm
Print Post Print Post  
Hi -

I am having a difficult time using programming to be executed "on form change."

My need is simple.  If indeed I make a change to any of the data on a form I need my Last Udate Layout Element to be updated to reflect the current date.

I thought the programming would be simple and used:

Code
Select All
Last Updated = @date 



The problem is that if I am simply searching through a stack of records, Sesame seems to think that the form has changed as soon as I navigate to the next record and changes the Last Updated element of the previous (simply viewed but not changed) form.  This, of course, is not acceptable.

Am I overlooking something simple (I hope)?


  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: On Form Change Programming
Reply #1 - Mar 4th, 2005 at 6:55pm
Print Post Print Post  
Hello Spencer,

Take a look at your other programming events particularly the Form On Form Entry event and your Form on Form Exit event to see if they are changing any element values.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: On Form Change Programming
Reply #2 - Mar 4th, 2005 at 7:24pm
Print Post Print Post  
Ray -

I have carefully gone through every one of my programming events twice now and cannot find anything that should cause an automatic change to the record.

The only on form entry events that are programmed would be to calculate age (or years since an event occured, such as a wedding, etc.)

The code (in this case for age) is simply:

Code
Select All
if Birthdate <> ""

 Age = @year(@date)-@year(Birthdate)-((@month(@date)<@month(Birthdate))
 or (@month (@date) = @month(Birthdate) and @dom(@date)<@dom(Birthdate)))
 



I realize now (and didn't before) that if there were a date in one of the programmed layout elements, this would automatically trigger a "form change."

In any event, this does not seem to be the "problem" because even if a form has no dates on it (and therefore no progamming should be executed) the Last Update field is still modified.

It is, of course, possible that I'm overlooking something in the other programming, but as I said, I checked it twice, very thoroughly each time, and just can't see anything that would automatically change a form (except for the date codes as mentioned above).

  

- Spencer

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


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: On Form Change Programming
Reply #3 - Mar 4th, 2005 at 7:44pm
Print Post Print Post  
It seems like your calculated age is overwriting the existing value in the Age.

Why don't you assign the calculated age to a variable and then conditionally update it only if it is needed?

var vAge as Int
vAge = (Your Code)

If Age <> vAge then
Age = vAge

See if this makes any difference.
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: On Form Change Programming
Reply #4 - Mar 4th, 2005 at 7:56pm
Print Post Print Post  
Quote:
Code
Select All
if Birthdate <> ""

 Age = @year(@date)-@year(Birthdate)-((@month(@date)<@month(Birthdate))
 or (@month (@date) = @month(Birthdate) and @dom(@date)<@dom(Birthdate)))
 




Hello Spencer,


The "or (@month (@date) = @month(Birthdate) and @dom(@date)<@dom(Birthdate))) " line in your code isn't going to do anything. You should also use @IsBlank() instead of <> "" so

Code
Select All
If Not @IsBlank(Birthdate) Then 



Do you have any unbound combo boxes on this form?

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: On Form Change Programming
Reply #5 - Mar 4th, 2005 at 8:38pm
Print Post Print Post  
Ray -

I've said it before and I'll say it again, you guys are GREAT!

I simply replaced:

Code
Select All
if Birthdate <> ""  



with

Code
Select All
If Not @IsBlank(Birthdate) then  



(I don't think the "then" is needed; however, it makes it clearer for me).

That, alone WOIKED!  I'm assuming that the <>"" was being ignored and, therefore, the programming was always being executed.

That makes me a bit curious though.  If the @isblank is preferred, then why isn't the <>"" simply eliminated from the programming?  Or ... is there an appropriate use of <>"" in preference to @isblank and, if so, could you tell me what criteria should be used to determine which command is chosen?

Also, you said that:

Quote:
The "or (@month (@date) = @month(Birthdate) and @dom(@date)<@dom(Birthdate))) " line in your code isn't going to do anything.


I thought that it was needed to not just consider the current year vs the birth year but also the month and day as well.  Now that I look at it though it seems that there would need to be a "then" portion of the statement (and perhaps an "else" portion, as well).  I know that in Q&A I used similar programming so that the age was accurate "to the day."   It would add a year to an existing age on the birthday only and not a day before. 

Can you suggest how to modify it to accomplish what I want (preferably along the same lines and not using SBasic)?

BY THE WAY, when I went back to my database (after reconciling the DSR file), it was correctly sorted!!!   Grin

You asked whether there were any command buttons but I wonder whether that is still important.  Yes, I have five or six and will be adding more.  The programming for them is executed "on entry" (clicking on the button).   Any special reason for asking (other than for a possible programming problem in one of those layout elements, that might have caused the form change)?

Bharat -

I appreciate your suggestion and it might well work; however, I did not try it.  Since Ray's suggestion made it much easier to change the programming statements (and there were six of them), I simply used it.  Thanks, very much, for helping though.  I appreciate all input and learning alternative ways of accomplishing the same goal.



  

- 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: On Form Change Programming
Reply #6 - Mar 4th, 2005 at 8:45pm
Print Post Print Post  
Quote:
That makes me a bit curious though.  If the @isblank is preferred, then why isn't the <>"" simply eliminated from the programming?  Or ... is there an appropriate use of <>"" in preference to @isblank and, if so, could you tell me what criteria should be used to determine which command is chosen?


@IsBlank is type-safe. In Q&A, under the hood, everything is really a string (text). In Sesame, a date is a date, a number is a number, etc. Therefore, comparing a non-text value like a date to "" (a zero-length string) may not have the intended result. @IsBlank, however, works on any type of data.
  

- 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: On Form Change Programming
Reply #7 - Mar 4th, 2005 at 8:53pm
Print Post Print Post  
Hi "Hammer"

I appreciate the feedback; however, since @isblank is fool-proof and <>"" is not .... I am wondering why it still exists and if there is any occasion when it would be better to use <>"" in preference to @isblank( ).  I have to assume that if it is still available (even though "flawed" so to speak) there must be a reason for continuing to make it available.

Wait a minute:  "Hammer", "Ohio",  "Position: Lanticans."  Are you by any chance Erika Yoxall?  If so, I am extremely eager to speak with you about the upcoming training you are planning.

So, if you are the "right person," I would very much appreciate your letting me know where to call you .. or, of course, you are welcome to call me at (813) 286-8498.
  

- Spencer

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


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: On Form Change Programming
Reply #8 - Mar 4th, 2005 at 9:00pm
Print Post Print Post  
Quote:
I have to assume that if it is still available (even though "flawed" so to speak) there must be a reason for continuing to make it available.


I guess to make the programming in Sesame backwards compatible with Q&A.
  
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 Change Programming
Reply #9 - Mar 4th, 2005 at 9:01pm
Print Post Print Post  
Quote:
Wait a minute:  "Hammer", "Ohio",  Business - "Lanticans."  Are you by any chance Ericka Yoxall?  If so, I am extremely eager to speak with you about the upcoming training you are planning.


Yep, it's me. I'll be announcing the class schedules and accepting signups soon. If you have specific questions about the classes, my email address is erika@hammerdata.com.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: On Form Change Programming
Reply #10 - Mar 4th, 2005 at 9:03pm
Print Post Print Post  
Computer languages need to support consistent syntax, even where that syntax may not be the ideal. The construct <> (not equal) can have any legal expression on either side of the operator - much like a plus sign "+" can have any numeric on either side, even though using a plus while operating on a negative number results in a subtraction. In other words, we support it because it would be inconsistent not to.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: On Form Change Programming
Reply #11 - Mar 4th, 2005 at 9:15pm
Print Post Print Post  
Thanks "Cow" - undstood (I think)!  It seems to me, then, that I am perfectly safe (for Sesame programming purposes) in always "sticking with" @isblank() rather than <>"". 

Erika -  Great - I'm on my way to my e-mail program.
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: On Form Change Programming
Reply #12 - Mar 4th, 2005 at 9:22pm
Print Post Print Post  
Spencer,

I think this is what you want.

 
Code
Select All
If Not @IsBlank(BirthDate) Then
{
	If (@Month(BirthDate) < @Month(@Date)) Or ((@Month(BirthDate) = @Month(@Date)) And (@DOM(BirthDate) <= @DOM(@Date))) Then
	{
		Age = @Year(@Date) - @Year(BirthDate) + 1
	}
	Else
	{
		Age = @Year(@Date) - @Year(BirthDate)
	}
} 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: On Form Change Programming
Reply #13 - Mar 4th, 2005 at 9:48pm
Print Post Print Post  
Ray -

Something very interesting.  I went back to my Q&Answerman database and apparently I had originally gotten that programming (that I had been using) from a Q&A Technical Bulletin which, I guess, was issued by Symantec.  Apparently, it was "flawed" and subsequently updated in a "Technical Tip" which they also issued.

I also found the Symantic Technical Tip on calculating age that goes into more detail and is easier to understand.

I have not yet tried the programming you provided; however, it "sounds" very familiar, so I am hoping that that is the definitive code I was looking for.

I will make the change right away; however, it may be a while before I can do complex "testing" to validate it under all situations.  Once done, I'll provide feedback.

Geez!  You guys sure are keeping me busy.  I am enjoying Sesame so much (as I did Q&A) that I can't seem to tear myself away from it.   Smiley
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
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 Change Programming
Reply #14 - Mar 4th, 2005 at 10:51pm
Print Post Print Post  
For every rule there is an exception Spencer:
Don't always use @IsBlank. 

That only works for Layout Elements.

Still need to use <>"" for variables.
---------------------------------
From the supplement documentation, page 22:

@IsBlank(element)
Type: Miscellaneous
Parameters:Layout Element as ElementRef
Returns: Boolean
  



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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: On Form Change Programming
Reply #15 - Mar 4th, 2005 at 11:11pm
Print Post Print Post  
Bob -

THANK YOU!!!!

That makes me feel better, actually.  I would hate to see programming that isn't necessary when there is something better. 

So, we haven't really made an "exception" to the rule ... we simply "modified" the rule.  lol

Seriously, it's good to know that it does, indeed, serve a useful purpose and I'm glad to know the distinction.

Besides the "fun" I'm having with Sesame, it's also nice to be in touch with you again.

Sesame is driving me crazy though.  I was just thinking ... I'm leaving my computer - I've got to eat.  And I just remembered that I didn't change my "age calculation" programming which I MUST do RIGHT NOW.  Will I ever recognize my "life" again?   lol
  

- 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: On Form Change Programming
Reply #16 - Mar 5th, 2005 at 1:39pm
Print Post Print Post  
Quote:
For every rule there is an exception Spencer:
Don't always use @IsBlank. 

That only works for Layout Elements.

Still need to use <>"" for variables.
---------------------------------
From the supplement documentation, page 22:

@IsBlank(element)
Type: Miscellaneous
Parameters:Layout Element as ElementRef
Returns: Boolean


Bob is correct. However, just to elaborate on what he says above...

You need to test your variables in a way appropriate to their type.
String
If vMyVar <> ""

Int or Double
If vMyVar > 0

... and so on.

As with LEs, testing a numeric variable by comparing it to "" may have unexpected results.
  

- 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: On Form Change Programming
Reply #17 - Mar 10th, 2005 at 11:39pm
Print Post Print Post  
Ray -

I hope you see this because I am somewhat confused regarding the programming to calculate age, based on date of birth.  Earlier I indicated that I was using the following code:

Code
Select All
if Birthdate <> ""

 Age = @year(@date)-@year(Birthdate)-((@month(@date)<@month(Birthdate))
 or (@month (@date) = @month(Birthdate) and @dom(@date)<@dom(Birthdate)))
  



You said:

Quote:
The "or (@month (@date) = @month(Birthdate) and @dom(@date)<@dom(Birthdate))) " line in your code isn't going to do anything. 


On looking at the code, I thought that you might be right because I didn't see any conditions applied such as 'then/else'.

You recommended the following code (which to me looked right):

Code
Select All
If Not @IsBlank(BirthDate) Then
{
     If (@Month(BirthDate) < @Month(@Date)) Or ((@Month(BirthDate) = @Month(@Date)) And (@DOM(BirthDate) <= @DOM(@Date)))

     Then  {   Age = @Year(@Date) - @Year(BirthDate) + 1  }    Else  {   Age = @Year(@Date) - @Year(BirthDate)  } }    



So, I tried it and it made me a year older.  I tried every possible variation of the code I could think of (taking into account the month and day, as well of the year) and, for the life of me, I could not get it to come out right.

So, I went back to this:
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))) 



I tried it and my age was back to what it should be.  I then tested every possible scenario.  On March 10, 2005, for example, a birthdate of March 10 2003 (or earlier) reports the age as 2.  A birthdate of March 11, 2004 (or later) reports the age as 1. 

I even played with leap year scenarios (including changing my computer clock to February 29th 2004) and everything seemed to check out appropriately.

I am just wondering whether the way the code is constructed, there is an 'implied' if/then/esle condition because, as I said, it appears to work flawlessly.  If the 'or" portion of the code did not work, then I would think I would not get accurate results right down to the actual birthday.

Any thoughts about this? ... as I'm always trying to learn more about and better understand any code that I use.

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: On Form Change Programming
Reply #18 - Mar 11th, 2005 at 12:54am
Print Post Print Post  
Spencer,

You original code works because it's doing something tricky. The problem is that, because it's tricky, it's also difficult to understand and maintain.  I'll resolve it for you step-by step so you can see how it works.

Assume that Birthdate = Feb 12, 1969

You start with this:
Age = @YEAR(@DATE) - @YEAR(BirthDate) - ((@MONTH(@DATE) < @MONTH(BirthDate)) or (@MONTH(@DATE) = @MONTH(BirthDate) AND @DOM(@DATE) < @DOM(BirthDate)))

If we resolve all the @Year, @Month, etc., we end up with this:
Age = 2005 - 1969 - ((3 < 2) or (3 = 2 AND 10 < 12))

Here's where the trick comes in. Each of the boolean expressions below (like 3 < 2) resolves to True (1) or False (0). Since 3 < 2, the first expression below resolves to False or 0. The whole things resolves as follows:
Age = 2005 - 1969 - ((0) or (0 AND 1))

The last expression is (0 AND 1). For an expression like this which uses AND to be True, all it's parts must be True. In this case, one of the parts is False (0), so the whole thing resolves to 0.
Age = 2005 - 1969 - ((0) or (0))

The last remaining expression uses OR. If any of the parts are True, the whole thing is True. In this case, both parts are False, so the whole things resolves to 0.
Age = 2005 - 1969 - 0

Now, you have resolved all the expressions except the final subtraction. Notice that the final number is 0. If any of the bits above had been True, the last number would have been 1.
Age = 36

That's how the trick works.

The method Ray used is less slick, but it's also more obvious and easier to read. In specific, however, there is a  condition reversed, so you're getting funny results. Give this a try:
Code
Select All
If Not @IsBlank(BirthDate) Then
{
	If (@Month(BirthDate) < @Month(@Date)) Or ((@Month(BirthDate) = @Month(@Date)) And (@DOM(BirthDate) <= @DOM(@Date)))
	{
		Age = @Year(@Date) - @Year(BirthDate)
	}
	Else
	{
		Age = @Year(@Date) - @Year(BirthDate) - 1
	}
}
 



Or this:
Code
Select All
var vOffset as Int

vOffset = 0
If Not @IsBlank(BirthDate) Then
{
	If (@Month(@Date) < @Month(BirthDate)) Or ((@Month(@Date) = @Month(BirthDate)) And (@DOM(@Date) < @DOM(BirthDate)))
	  {
		   vOffset = 1
	  }
	Age = @Year(@Date) - @Year(BirthDate) - vOffset
}
 


  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged