Alpha Video Training
Results 1 to 27 of 27

Thread: Using function in a calculation problems

  1. #1
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Using function in a calculation problems

    Hello,
    I'm creating an application that help Fashion designer to calculate data when crating a sloper for the garment, in one of the fields is needed the following calculation,
    Example:
    Bust = 33"
    Underbust = 27"
    A: Cup size = If the underbust is an ODD number add 5", and if the result is even then add 4" in our example the number is 27" so we add 5" the result then is 32".
    New Underbust number is 32"
    B:next: Bust - New UnderBust 33"-32"= 1"
    If the result = 1" the cup size is "A"
    If the result = 2" the cup size is "B"
    If the result = 2" the cup size is "B"
    In our case the Cup Size is "A"
    In excel is very simple:
    A: =IF(ISODD(UnderBust),UnderBust+5",UnderBust+4")
    B: =IF((Bust-UnderBust)=1,"A",IF((Bust-UnderBust)=2,"B","C"))

    In
    Alpha anywhere v 12 the ISODD function is not recognize.
    Can anybody Help me fix this issue?

    Thanks
    Samuel Eskenasy

  2. #2
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,047

    Default Re: Using function in a calculation problems

    Use Mod() to determine if it is even or odd.
    Andrew

  3. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Using function in a calculation problems

    ? mod(int(-1),2)
    = -1
    ? mod(int(2.5),2)
    = 0
    ? mod(int(5),2)
    = 1
    So if mod(int(some_value),2) <> 0 the number ISODD.
    There can be only one.

  4. #4
    Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,596

    Default Re: Using function in a calculation problems

    See Stan's solution to this here:

    http://www.alphasoftware.com/alphafo...ght=odd+number

    Edit: Geeze, where else can you get this much help this fast?
    -Steve


  5. #5
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Using function in a calculation problems

    Thanks for the citation, Steve. Seems the Excel ISODD() operates a bit differently with fractional parts so I tweaked the logic a bit.
    Last edited by Stan Mathews; 04-06-2015 at 03:40 PM.
    There can be only one.

  6. #6
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Using function in a calculation problems

    i see you are in mobile & Browser forum, where is this calculation being done
    in an ux or an updatable grid? if so, then you may want to consider writing the code in javascript. which will not require a callback to the server.
    Last edited by GGandhi; 04-07-2015 at 07:51 AM.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  7. #7
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    Thanks for responding, I'm checking to see if it works.
    Samuel

  8. #8
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    Quote Originally Posted by GGandhi View Post
    i see you are in mobile & Browser forum, where is this calculation being done
    in an ux or an updatable grid? if so, then you may want to consider writing the code in javascript. which will not require a callback to the server.
    I add the calculation in a UX field calculation. But I'm really confuse with the mod() function(don't figure out how to place the data).

  9. #9
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Using function in a calculation problems

    IF(ISODD(UnderBust),UnderBust+5",UnderBust+4")

    would become

    IF(mod(int(UnderBust),2)>0,UnderBust+5",UnderBust+4")
    There can be only one.

  10. #10
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    Quote Originally Posted by Stan Mathews View Post
    IF(ISODD(UnderBust),UnderBust+5",UnderBust+4")

    would become

    IF(mod(int(UnderBust),2)>0,UnderBust+5",UnderBust+4")

    I'd try your suggestion, an error massage "mod" is undefined .

  11. #11
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Using function in a calculation problems

    Then you're operating in an environment where xbasic functions aren't allowed. See post #6 about using javascript.

    Actually the earlier answer was not entirely correct.

    The expression should not have the " inch representation.


    IF(mod(int(UnderBust),2)>0,UnderBust+5,UnderBust+4)
    There can be only one.

  12. #12
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    Quote Originally Posted by Stan Mathews View Post
    Then you're operating in an environment where xbasic functions aren't allowed. See post #6 about using javascript.

    Actually the earlier answer was not entirely correct.

    The expression should not have the " inch representation.


    IF(mod(int(UnderBust),2)>0,UnderBust+5,UnderBust+4)

    I make the correction, and stillErrorMsg.PNG

  13. #13
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Using function in a calculation problems

    mod is an alpha function, highly doubt that it is available at the browser level.
    you should be doing this via javascript, otherwise you should do an ajaxcallback to the server where the function is available at the WAS.
    additionally you need two step process these two should be able to be combined in one javascript call and the size is captured at the end.
    again you did not answer my original question in post number 6. is this on an ux or updatable grid?
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  14. #14
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    I add the calculation in a UX field calculation. #8

  15. #15
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Using function in a calculation problems

    okay this is what you do
    say if you have three fields
    bust a number, under_breast a number and cup a character fields, then in the under_breast onChange event define an inline javascript and copy the following.
    Code:
    var underBreast = {dialog.object}.getValue('UNDER_BREAST’);
    var onBust = {dialog.object}.getValue(‘BUST’);
    var newUnderBreast = null;
    if (underBreast%2 == 0) {
       newUnderBreast = parseInt(underBreast) + 4;
    } else {
      newUnderBreast = parseInt(underBreast) + 5;
    }
    var cupSize = null;
    if (onBust - newUnderBreast == 1) {
         cupSize = 'A';
    }
    else if (onBust - newUnderBreast == 2) {
        cupSize = 'B';
    }
    else  {
       cupSize = ‘C’;
    }
    
    {dialog.object}.setValue(‘CUP’, cupSize);
    and you can change the condition of C as you please.

    i am not going to be at my work computer till saturday any fine tuning will take time for me to do.
    let us know how it goes.
    Last edited by GGandhi; 04-09-2015 at 07:14 AM.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  16. #16
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    I'd try and have some error.
    Let me make it clear again.
    There is a condition by one of the calculation: If UnderBust is an even add 4" if the UnderBust is odd Add 5" if The UnderBust is in between Roundup
    Then I get a result number. This number I subtract fro Bust And if the difference is 1" then Cup size is "A" if 2" then "B" if 3" then "C" else "C"
    My problem is in the first part of the calculation and it's to add the correct number to UnderBust.
    I'll attached some image tha tyou can see the idee.(in mean time I put in my calculation a fix number (UnderBust +10.2cm)(4.5")
    calcimage.PNG
    CupCalc.PNG

    Thanks again
    Samuel

  17. #17
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Using function in a calculation problems

    Code:
    var underBreast = {dialog.object}.getValue('UNDER_BREAST’);
    underBreast = Math.ceil(underBreast);
    var onBust = {dialog.object}.getValue(‘BUST’);
    var newUnderBreast = null;
    if (underBreast%2 == 0) {
       newUnderBreast = parseInt(underBreast) + 4;
    } else {
      newUnderBreast = parseInt(underBreast) + 5;
    }
    var cupSize = null;
    if (onBust - newUnderBreast == 1) {
         cupSize = 'A';
    }
    else if (onBust - newUnderBreast == 2) {
        cupSize = 'B';
    }
    else if (onBust - newUnderbreast == 3) {
       cupSize = 'C';
    else  {
       cupSize = ‘D’;
    }
    
    {dialog.object}.setValue(‘CUP’, cupSize);
    the round up was not mentioned earlier, so i modified the code.
    also with this javascript code, you do not need to calculate the cup size it will automatically insert in the cup field.

    when i get a chance i will look into how to get any in between number to up-round it.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  18. #18
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,309

    Default Re: Using function in a calculation problems

    Quote Originally Posted by esamuel View Post
    I'd try and have some error.
    Let me make it clear again.
    There is a condition by one of the calculation: If UnderBust is an even add 4" if the UnderBust is odd Add 5" if The UnderBust is in between Roundup
    Then I get a result number. This number I subtract fro Bust And if the difference is 1" then Cup size is "A" if 2" then "B" if 3" then "C" else "C"
    My problem is in the first part of the calculation and it's to add the correct number to UnderBust.
    I'll attached some image tha tyou can see the idee.(in mean time I put in my calculation a fix number (UnderBust +10.2cm)(4.5")
    calcimage.PNG
    CupCalc.PNG

    Thanks again
    Samuel
    Hey Samuel,

    What I don't quite follow is where your "either or" calculation is coming from for adding to the new underbust value. It sounds like there's more going on in your calculations than you've initially indicated and the screenshot really doesn't provide extra information as to what maths are involved. Though, maybe that's because the discussion is in inches but your images are showing cm.

    I put together a component that tries to do what you're describing. It uses Calculated Field Expressions to calculate the new underbust value as well as the cup size. Is this what you were looking for?

    EDIT: there was an error in my calculations if "cm" was selected from the dropdown. This zip contains the fixed version:
    underbust.zip
    Last edited by TheSmitchell; 04-09-2015 at 12:11 PM.
    Alpha Anywhere latest pre-release

  19. #19
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    OK, That work.
    Did I say Genus?
    Now I have to figure out how and were to put it in my app.

    Thanks

  20. #20
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    Hi, Sarah,
    I implemented the code where it's belong, and it works.
    There is some changes that you can help me make:
    1) I need the default to be "cm"(I made changes in Unit control, but I need to change the JavaScript too, but the result was incorrect).
    let say I create client with data in "in" and like to see measurement in "cm" and going back to "in , the data was incrementing each time I made this changes.
    recordof .PNGrecordof1 .PNGrecordof2 .PNG
    I need to fix this incrementation.
    2) In the Calculation part You can see image , that when in "cm" the adding sum should be 10.2mm or 12.7mm , but it add 4" or 5" instead,( When the data is in "in" it's all correct.)
    Last edited by esamuel; 04-12-2015 at 04:12 AM.

  21. #21
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,309

    Default Re: Using function in a calculation problems

    Quote Originally Posted by esamuel View Post
    Hi, Sarah,
    I implemented the code where it's belong, and it works.
    There is some changes that you can help me make:
    1) I need the default to be "cm"(I made changes in Unit control, but I need to change the JavaScript too, but the result was incorrect).
    let say I create client with data in "in" and like to see measurement in "cm" and going back to "in , the data was incrementing each time I made this changes.
    recordof .PNGrecordof1 .PNGrecordof2 .PNG
    I need to fix this incrementation.
    2) In the Calculation part You can see image , that when in "cm" the adding sum should be 10.2mm or 12.7mm , but it add 4" or 5" instead,( When the data is in "in" it's all correct.)
    Ah.

    What you need to do is convert the data coming in, which is in cm, to inches:
    Code:
    var cmInAnInch = 2.54;
    underbust = Math.ceil(underbust/cmInAnInch);
    Do all the calculations in inches, then at the end, convert it back to cm:
    Code:
    return newUnderbust * cmInAnInch;
    In the case of the cup size calculation, you don't need to convert back to cm since you're returning a string. But for the new underbust, you would need to convert back if you're displaying it.

    If you wanted to do all the math in cm, then you can't use the floor or ceiling functions for rounding. Nor can you use the modulo operator (%) based on your requirement that lengths are rounded to the nearest *inch*. The math operators would round your numbers to the nearest cm.

    If you want the math that adds the 4" or 5" inches to work with the original cm data, you can store your inches calculations in separate variables and add the cm values to the original data that was given to the function. Also, I'm making the assumption that you meant 10.2cm and not 10.2mm (10.2mm would be 1.2cm and way smaller than 4"). If this assumption is false, then 10.2 and 12.7 need to be changed to 1.02 and 1.27 below:
    Code:
    function calcNewUnderbustAlt (underbust) {
    	var cmInAnInch = 2.54;
    	var underbustIn = Math.ceil(underbust/cmInAnInch);
    	
    	var newUnderbust = 0;
    	
    	// FYI: this does not round the cm value UP to the nearest inch before
    	// adding 10.2 or 12.7. It just adds 10.2 or 12.7.
    	if (underbustIn == 0) {
    		newUnderbust = 0;
    	} else if (underbustIn % 2 == 0) {
    		newUnderbust = underbust + 10.2;
    	} else {
    		newUnderbust = underbust + 12.7;
    	}
    	
    	return newUnderbust;
    }
    I updated the component I posted earlier to do the conversion to inches before mathing if the data was cm values after recognizing that Math.ceil() on a cm value didn't round to the nearest *inch*.
    Alpha Anywhere latest pre-release

  22. #22
    "Certified" Alphaholic CharlesParker's Avatar
    Real Name
    Charles Parker
    Join Date
    Dec 2012
    Location
    New Orleans, LA
    Posts
    2,060

    Default Re: Using function in a calculation problems

    dam sarah, nice work!
    NWCOPRO Nuisance Wildlife Control Software-My Application: http://www.nwcopro.com "I am not discouraged, because every wrong attempt discarded is another step forward."

  23. #23
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Using function in a calculation problems

    Code:
    var measurement = {dialog.Object}.getValue('MEASUREMENT');
    var bust = {dialog.Object}.getValue('BUST');
    var underBust = {dialog.Object}.getValue('UNDER_BUST');
    if (measurement == "centimeters") {
    	bust = bust/2.54;
    	underBust = underBust/2.54;
    }
    bust = Math.ceil(bust);
    underBust = Math.ceil(underBust);
    var newUnderBust = null;
    if (underBust%2 == 0) {
    	newUnderBust = parseInt(underBust) + 4;
    } else {
    	newUnderBust = parseInt(underBust) + 5;
    }
    var cupSize = null;
    switch(bust - newUnderBust) {
    	case 1:
    		cupSize = 'A';
    		break;  
    	case 2:
    		cupSize = 'B';
    		break;
    	case 3:
    		cupSize = 'c';
    		break;
    	case 4:
    		cupSize = 'D';
    		break; 
    	default:
    		cupSize = 'Z';
       }
    {dialog.Object}.setValue('CUP_SIZE',cupSize);
    here is the follow up on the code in post #17,
    it depends on 3 fields: measurement ( can be inches or centimeters on a dropdown control), bust, underbust and sets the value of the cupsize based on the information provided.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  24. #24
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Using function in a calculation problems

    take a look at this screen implementing the code, also I think you have an error in your image
    if you have bust 91 cm, under_bust at 74cm then the cup size should be B according to calculation I did.
    http://screencast.com/t/txQXlkbpT
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  25. #25
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    Quote Originally Posted by GGandhi View Post
    take a look at this screen implementing the code, also I think you have an error in your image
    if you have bust 91 cm, under_bust at 74cm then the cup size should be B according to calculation I did.
    http://screencast.com/t/txQXlkbpT

    Thank you for a very nice explanation.
    I'll put it to work and inform how it's going

    Samuel

  26. #26
    Member
    Real Name
    Samuel Eskenasy
    Join Date
    Nov 2006
    Location
    Tel Aviv, Israel
    Posts
    31

    Default Re: Using function in a calculation problems

    Quote Originally Posted by GGandhi View Post
    take a look at this screen implementing the code, also I think you have an error in your image
    if you have bust 91 cm, under_bust at 74cm then the cup size should be B according to calculation I did.
    http://screencast.com/t/txQXlkbpT

    Me again,
    Can you please send me a zip file of this so I can see all details more clearly?!!

  27. #27
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Using function in a calculation problems

    sorry sam I did not save the component I did not think you will need that.
    the important aspect is the code, that I gave you. but if that is not enough, you sent me an email, so you have access to me. please send all the measurements and desired results. this weekend I will put together a dialog and zip it to you ( this will be the first time I am sending a component, hopefully I will do right). remember again this will be in version 11. no panel cards etc.,
    Last edited by GGandhi; 04-29-2015 at 05:49 AM.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

Similar Threads

  1. Week and Month Calculation Problems - How to????
    By TTI in forum Alpha Five Version 7
    Replies: 9
    Last Post: 02-13-2007, 05:35 PM
  2. Calculation Problems
    By gerard1014 in forum Alpha Five Version 4
    Replies: 2
    Last Post: 02-07-2002, 11:03 AM
  3. Calculation problems
    By B Mac in forum Alpha Five Version 4
    Replies: 9
    Last Post: 09-26-2001, 10:15 AM
  4. Calculation Problems
    By Bill Rosendale in forum Alpha Five Versions 2 and 3
    Replies: 1
    Last Post: 05-09-2001, 11:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •