[Ch...] Posted July 15 Share Posted July 15 Hi everyone, I have passed PCM class and am a fairly avid PCM user, however I'm stuck at a simple task that is not working for me. I would like to assign a variable for a Z height of a point, then Assign a tolerance (0.010") then assign a variable for Min tolerance = MYVAR-TOL and max tolerance : MYVAR+TOL, because this code will likely be use on multiple parts and simplifies things. Doing the following, by adding 2 VARs that have numbers seems to just combine them, for example this code //Get Part Nominal Z value PTZ=formatL((getNominal("Point FIND Z").z),0,5) message("Z Nom is : "+PTZ) // assign var to max limit MAXZ=getNominal("Point FIND Z").z+0.010 message(MAXZ) //adding variables doesnt seem to work here TOL=0.0100 MXZ=TOL+PTZ message(MXZ) Assuming the PTZ = 9.3000 The message MAXZ = correct value 9.400, the message for MXZ (when I add 2 variables) is 0.0109.300 or something similar. If I tried PTZ+TOL it would show 9.3000.010. However when I try simple math such as : VAR1=3 VAR2=4 SUM=VAR1+VAR2 message(SUM) This produces expected result and message = 7. Am I missing something here, or should I avoid adding VARiables ? ❓ Thank you ! Link to comment Share on other sites More sharing options...
[An...] Posted July 15 Share Posted July 15 Hey Chris! The issue is data types! formatL / formatR / format return a string. The 2nd line, PTZ becomes a string. Which causes TOL to become a string when adding them together. It looks like when doing addition that involves a string, everything gets turned into a string. The number 9.3 becomes formatted to "9.300" The number 0.01 becomes "0.010" So "9.300" + "0.010" = "9.3000.010" Consider using round instead of format to keep the data type a number? If you have to display the number, maybe use format on the fly instead of assigning to a variable? PTZ = getNominal("Point FIND Z").z // or round(getNominal("Point FIND Z").z, 5) message("Z Nom is : " + formatL(PTZ, 0, 5)) Link to comment Share on other sites More sharing options...
[Ky...] Posted July 15 Share Posted July 15 Hello Chris, I think what is happening is the way you are defining PTZ is making it a string rather than a number. One way around it would be to define PTZ as "getNominal("Point FIND Z").z)" and then make another variable PTZString as "formatL(PTZ,0,5)". Alternatively I believe you can case the original PTZ as a number if you use "val(PTZ)" at that end part. I hope you find this useful. Link to comment Share on other sites More sharing options...
[Ch...] Posted July 15 Author Share Posted July 15 Please sign in to view this quote. Andrew, got it makes perfect sense. Thanks, Chris Link to comment Share on other sites More sharing options...
[Ch...] Posted July 15 Author Share Posted July 15 Please sign in to view this quote. Thanks guys, yes makes perfect sense now. Mondays I guess ... 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