HaroonMalik Posted September 20, 2023 Share Posted September 20, 2023 Helle Everyone! I am using macros in my GFA summary sheet for my project. I am able to add or subtract multiple areas by using + or - symbols in the macro. Further, I am also able to multiply two values by using " * " symbol too. However, unfortunately the symbols "÷" or "/" do not work for a division operation. I will do appreciate if someone could help with the division of a couple of values in a macro. Regards Link to comment Share on other sites More sharing options...
Chopsaw Posted September 20, 2023 Share Posted September 20, 2023 You may need to confirm what version you are using and a little more about the exact values you are dividing. "/ " Is the correct format for division in Ruby but it needs to be the correct data you are dividing. Link to comment Share on other sites More sharing options...
HaroonMalik Posted September 20, 2023 Author Share Posted September 20, 2023 thanks for reply. i am using for example; %$a=area% Area of polyline say"a" %$b=area% Area of polyline say"b" %$a+$b% Total area of a+b %$a+$b% Total area of a+b %$a*$b% Multiplication of a&b These all work, However %$a/$b% Division of a&b Does not Link to comment Share on other sites More sharing options...
Chopsaw Posted September 20, 2023 Share Posted September 20, 2023 Hummm.... I am not sure what is going on as it seems to work for me in X12. You may need to post a test plan. Actually the division works but the multiplication seems to be creating an issue. Had to tweak the multiplication to get it to work without interference from the measurement class. axb=%($a.to_f*$b.to_f).round% 1 Link to comment Share on other sites More sharing options...
HaroonMalik Posted September 21, 2023 Author Share Posted September 21, 2023 Thank you Chopsaw for your reply. For me the multiplication works fine with asterik " * " sign. Unfortunately, division is not working in the same way by"/" or "÷" sign. Link to comment Share on other sites More sharing options...
Chopsaw Posted September 21, 2023 Share Posted September 21, 2023 Just now, HaroonMalik said: Thank you Chopsaw for your reply. For me the multiplication works fine with asterik " * " sign. Unfortunately, division is not working in the same way by"/" or "÷" sign. Give it a try with the same formatting as I used for the multiplication and see if that works. Otherwise I would need to look at your setup or hope one of the macro gurus can spot the issue. 1 Link to comment Share on other sites More sharing options...
Joe_Carrick Posted September 21, 2023 Share Posted September 21, 2023 It's likely that there's a problem with the value type of $a or $b. If $b isn't either a float or integer then the division will fail. I'm pretty sure the Measurement Class doesn't provide for dividing by a measurement. 1 1 Link to comment Share on other sites More sharing options...
HaroonMalik Posted September 21, 2023 Author Share Posted September 21, 2023 I will give it a try in a new file to be sure if there is no issue with the value type. Appreciate. Thanks Link to comment Share on other sites More sharing options...
Doug_N Posted September 21, 2023 Share Posted September 21, 2023 Area = % $testarea = area % Area = % $testarea = area/2 % This seems to work for a area bound by a rectangular polygon. Please post the ruby macro that you are trying to use? This could be a formatting issue. 1 Link to comment Share on other sites More sharing options...
Solution Doug_N Posted September 21, 2023 Solution Share Posted September 21, 2023 Ah, I see the problem, you are dividing one area by another. Mind you, this is for X-15, the best release of CA ever!!! 1 Link to comment Share on other sites More sharing options...
HaroonMalik Posted September 22, 2023 Author Share Posted September 22, 2023 Thanks a lot Doug_N. It worked.....waao. However, may i ask one more help?. The answer is in up to 7 places after decimal as shown in the image. I have rounded the answers that applies to the individual polygon but does not apply on the answer as shown. Appreciate your time and help. Link to comment Share on other sites More sharing options...
Chopsaw Posted September 22, 2023 Share Posted September 22, 2023 Haroon, I think it may just be a fluke that it worked this time. I can't really explain it or fully understand it but it is likely the same reason that the division worked for me and not you and then the multiplication failed for me and not for you. If you go back and take a look at my corrected formula, I think that is what you will need to use for consistent results. I also showed how to correctly do the rounding you are now asking for. 1 Link to comment Share on other sites More sharing options...
Doug_N Posted September 23, 2023 Share Posted September 23, 2023 The code for rounding numbers in a simple way is %variable. round(2)% where the variable is rounded to 2 decimal places. This works for all variables types it seems. 1 Link to comment Share on other sites More sharing options...
Doug_N Posted September 23, 2023 Share Posted September 23, 2023 Joe makes a good observation in his comment about variable types. You can't divide an integer or floating value by a length or by an area. But you can divide a length or area by any of the following: an area, a length, an integer or a floating point variable. 1 Link to comment Share on other sites More sharing options...
Joe_Carrick Posted September 23, 2023 Share Posted September 23, 2023 2 hours ago, Doug_N said: Joe makes a good observation in his comment about variable types. You can't divide an integer or floating value by a length or by an area. But you can divide a length or area by any of the following: an area, a length, an integer or a floating point variable. There are a few more things to consider: volume(cu ft)/area(sq ft) = linear (inches) volume(cu ft)*area(sq ft) = derived (nonsense) volume(cu ft)/linear(inches) = area (sq ft) volume(cu ft)/volume(cu ft) = ratio (unitless) area(sq ft)/linear(inches) = linear (inches) area(sq ft)*linear(inches) = volume (cu ft) area(sq ft)/area(sq ft) = ratio (unitless) area(sq ft)/volume(cu ft) = derived (nonsense) area+/-linear = error, not allowed area+/-volume = error, not allowed volume+/-linear = error, not allowed linear(inches)/area(sq ft) = derived (nonsense) linear(inches)/volume(cu ft) = derived (nonsense) There are probably a few more Generally it's best to know what the units are and, if necessary convert to floating point values before the calculations. 1 Link to comment Share on other sites More sharing options...
Doug_N Posted September 23, 2023 Share Posted September 23, 2023 29 minutes ago, Joe_Carrick said: There are a few more things to consider: volume(cu ft)/area(sq ft) = linear (inches) volume(cu ft)*area(sq ft) = derived (nonsense) volume(cu ft)/linear(inches) = area (sq ft) volume(cu ft)/volume(cu ft) = ratio (unitless) area(sq ft)/linear(inches) = linear (inches) area(sq ft)*linear(inches) = volume (cu ft) area(sq ft)/area(sq ft) = ratio (unitless) area(sq ft)/volume(cu ft) = derived (nonsense) area+/-linear = error, not allowed area+/-volume = error, not allowed volume+/-linear = error, not allowed linear(inches)/area(sq ft) = derived (nonsense) linear(inches)/volume(cu ft) = derived (nonsense) There are probably a few more Generally it's best to know what the units are and, if necessary convert to floating point values before the calculations. Joe, Have you considered doing a class on the use of Ruby in CA? I bet lots of us would sign up for it. 1 2 Link to comment Share on other sites More sharing options...
dskogg Posted September 23, 2023 Share Posted September 23, 2023 I would sign up for sure! 1 Link to comment Share on other sites More sharing options...
HaroonMalik Posted September 23, 2023 Author Share Posted September 23, 2023 On 9/22/2023 at 12:45 PM, Chopsaw said: Haroon, I think it may just be a fluke that it worked this time. I can't really explain it or fully understand it but it is likely the same reason that the division worked for me and not you and then the multiplication failed for me and not for you. If you go back and take a look at my corrected formula, I think that is what you will need to use for consistent results. I also showed how to correctly do the rounding you are now asking for. Yes, you might be correct. The results often are not as expected at certain times. Similar method works the other day. I really appreciate valuable information and help offered by you all. Many Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now