Hot Topic (More than 10 Replies) Sesame 2.0 - Numbers Problem (Read 1538 times)
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Sesame 2.0 - Numbers Problem
Jul 8th, 2007 at 9:56pm
Print Post Print Post  
Hi -

First, I want to say how thrilled I am with my new copy of Sesame 2.0.  I'll be glad when I get some experience with it, under my belt.  In the meantime, I am delighted with the table view; that alone makes it worth the money.

I am, however, having a problem with a number element.  Three fields are involved:  Unit, Price Per Unit, and Cost.

When I enter whole numbers in the Unit field, it multiplies the Price per unit and places the total in the Cost field.  It works fine.

However, when I enter a fraction, the fraction is ignored.  So if I enter .25 (x $8.00) the cost is shown as $0.00

If I enter 1.25 (x 8.00) the cost is shown as $8.00.  Help!

Thanks!
  

- Spencer

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



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Sesame 2.0 - Numbers Problem
Reply #1 - Jul 8th, 2007 at 11:22pm
Print Post Print Post  
It sounds like you may be using a variable for Unit that is declared as Int type rather than Money type. Or possibly, the Unit element's format is set to zero decimal places.


PS: I know I wrote Money type versus Double. I don't like like Doubles when dealing with money. Wink
  


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



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Sesame 2.0 - Numbers Problem
Reply #2 - Jul 8th, 2007 at 11:39pm
Print Post Print Post  
Ahhh! I just tested this, and I think I see the same thing.

Go into Manage Fields, select Change Field Type, select your Unit field, and set it to Money. Then test it, and let me know if that fixes it.
  


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



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Sesame 2.0 - Numbers Problem
Reply #3 - Jul 8th, 2007 at 11:52pm
Print Post Print Post  
Sorry about all the separate posts.  Cheesy

Can you also show us the code that is calculating the total?

You may also see this problem if you are multiplying an element bound to Number type with an element bound to Money type.

For example, if you have
Total = @TM(Qty * Price)

where Total is bound to Money, Qty is bound to Number, and Price is bound to Money; you will see those results.

But, if you use the following instead, it will work correcty.
Total = @TM(Qty) * Price

So, the solution is to either convert the types to be the same before performing math on them; or to make the fields all the same type to begin with. Does that make sense?
  


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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Sesame 2.0 - Numbers Problem
Reply #4 - Jul 9th, 2007 at 12:49am
Print Post Print Post  
Carl -

Nice to hear from you.

I think I tried what you said, but "no cigar."  Once again, there are 3 fields involved:  (1) Quantity = How many of an item or what fraction of a pound (it is bound to number)  (2) Item Cost = The cost of one item or the cost per pound (it is bound to money  (3) Cost = the cost for the number of items (or the fraction of a pound) purchased (it is bound to money)

My code (Qty: On Element Exit), which worked in version 1.X was simply:

Code
Select All
If not @isblank(Qty) then
Cost = Qty * Item Cost

If @isblank(Qty) then clear(Cost) 



I tried using this, but it did not make any difference.

Code
Select All
If not @isblank(Qty) then
Cost = @tm(Qty) * Item Cost

If @isblank(Qty) then clear(Cost) 



I did try converting the qty element itself from number to money and that DID work, but my quantity field was $1.00 (I don't remember how fractions appeared but I would assume something like $0.25).

In any event, while that gives me the correct Cost, it is not acceptable in appearance.

I am wondering whether this could be a bug.

Since it is very rare that you would ever multiply money by money ($4.00 x $4.00)??? it is only logical that you should be able to multiply number x money.
  

- Spencer

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



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Sesame 2.0 - Numbers Problem
Reply #5 - Jul 9th, 2007 at 1:33am
Print Post Print Post  
Quote:
I tried using this, but it did not make any difference.

Code
Select All
If not @isblank(Qty) then
Cost = @tm(Qty) * Item Cost

If @isblank(Qty) then clear(Cost)  


That should work. I just cut and pasted your sample into my test app, modified the names, and it works. Are you sure you saved the design before previewing?

In any case, that doesn't matter because you can simply reformat what you have now, to look the way you want.
Follow these steps:
1. Open the form in designer.
2. Click on the Qty element.
3. Click on the FORMAT tab under PROPERTY EDITOR.
4. In the DISPLAY FORMAT drop-down, select CUSTOM FORMAT.
5. Set DECIMAL PLACES to what you want (probably 2).
6. Leaving the CURRENCY SYMBOL box blank, click on the down-arrow, then on SET CURRENCY SYMBOL.
7. Change GROUP DIGITS to NO if you want.
8. Click on the Qty element, and type 1.25, then press Enter. (This is optional, but it will let you see the results right away, without needing to preview. If you make any other changes to the properties, you will need to change a digit or 2, for it to update with the new format.)
9. Once you have it the way you want, don't forget to SAVE the design.

  


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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Sesame 2.0 - Numbers Problem
Reply #6 - Jul 9th, 2007 at 2:03am
Print Post Print Post  
Carl -

I haven't tried that, because it seems to me that (even if it did work) my numbers would appear as 1.00 and I don't want that.  

When it was a number field 1 would appear as 1 and .25 would appear as 0.25 (which I'm not crazy about, but at least it worked and wasn't as "offensive" as 1.00).

I would really like to know whether this is a bug or not.

Thanks!
  

- Spencer

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



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Sesame 2.0 - Numbers Problem
Reply #7 - Jul 9th, 2007 at 2:49am
Print Post Print Post  
Quote:
I haven't tried that, because it seems to me that (even if it did work) my numbers would appear as 1.00

Yes, you're correct. It will display with the zeros. I would change the Qty field back to Number type, and be sure to wrap it in @TM() before performing math. I was able to make it work doing that.

Quote:
I would really like to know whether this is a bug or not.

No, I don't think that it's a bug. The reason it worked in version 1.x, is because NUMBER and MONEY fields were both floating point numbers. In version 2.0, MONEY is now a fixed point number (better for dealing with currency).

This means you should convert NUMBER fields or DOUBLE variables (with the typecasting command) before you perform math on them in conjuction with MONEY fields or the new MONEY type variable.
  


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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Sesame 2.0 - Numbers Problem
Reply #8 - Jul 9th, 2007 at 4:49pm
Print Post Print Post  
Carl -

I found out why the @tm coding wasn't working.  Besides having the code in the Qty: On Element Exit field, I also had it in the Item Cost: On Element Exit Field.  I did that so that the Cost would be recalculated when there was a change in either the Qty field or the Item Cost field.  By changing it in both places, the Cost is now correctly calculated.

I also (coincidently) modified my programming to:

Code
Select All
	If not @isblank(Qty) then
	Cost = @tm(Qty) * Item Cost
	else
	Clear(Cost)

 



Unfortunately, I am left with two problems (perhaps because of the change in type of decimal point ... which, admittedly, I don't know much about and don't necessarily want to). lol

Now, because I made my number field two decimal points, even as a number field I get 1.00 instead of 1 - and I really don't like this.  I only want the two decimal places to appear if the value is a whole number.  If I change the decimal points to "0" then I can't enter fractions when I need them.

Also, even though I say to CLEAR the Cost field (when Qty is blank) I am getting $0.00.

I would really like to have a way to resolve these two (for me) problems.

Also, while I hate to be "stubborn" about it ... it just doesn't make sense to have to convert a number field to money just to perform math.  Shouldn't it be possible for the database to contain "behind-the-scene" programming for us, if it is absolutely necessary?   It seems like it is an "anomoly" (compared to most programming) to have to do this.

I would love to hear from Ray or Mark about this.

Thanks!
  

- 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: Sesame 2.0 - Numbers Problem
Reply #9 - Jul 9th, 2007 at 5:43pm
Print Post Print Post  
SpencerWulwick wrote on Jul 9th, 2007 at 4:49pm:
Now, because I made my number field two decimal points, even as a number field I get 1.00 instead of 1 - and I really don't like this.  I only want the two decimal places to appear if the value is a whole number.  If I change the decimal points to "0" then I can't enter fractions when I need them.


Set the format of the element to be SYSTEM and not the CUSTOM display format that was set earlier.

Quote:
Also, even though I say to CLEAR the Cost field (when Qty is blank) I am getting $0.00.


I just tested this here and Clear() does clear out a money element. Make sure you have no other programming setting the cost field.

-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: Sesame 2.0 - Numbers Problem
Reply #10 - Jul 9th, 2007 at 8:02pm
Print Post Print Post  
Ray -

Thanks much.

I changed the quantity back to system settings and it works as I would expect.  Also, don't know whether it is coincidental or I did something else without realizing it, but the clear(Cost) is now working and clears the field instead of showing $0.00.

That leaves my one remaining question about whether something can be done to change the programming when using math between numbers and money.

The situation, as it is, is even worse than I thought because I found that it not only affected my databases, but my reports with calculations as well.  If left as is, that would mean that I would have to go through not only every database, but every report within all my databases, as well.

Thanks!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged