Jump to content

Boolean expression question


---
 Share

Recommended Posts

I'm looking to add an a Boolean expression, or would I need a Logic Statement?

First, here are my presetting's;
*************************************************
LN = getRecordHead("order")

clearCAD()
dir = getActualInspectionDir()

Part_Size = inquireList("Which part number would you like to run?", "101221","101228")
selectCase Part_Size
case "101221"
readPCMFile(dir + "\101221.PARA")
loadCADFile(dir+"\101221.sab")

case "101228"
readPCMFile(dir + "\101228.PARA")
loadCADFile(dir+"\101228.sab")

endSelect
*************************************************
This is what I want to add;

if Part_Size=="101221"

setinspectionDrivingSpeed(30)

endif
******************************************************************************************
I've already got the "setinspectionDrivingSpeed(30)" in the feature presetting's.
I don't want the speed reduction if the operator chooses 101228. I'm not sure
if the syntax, or it's location are correct?
Link to comment
Share on other sites

I would have the expression in the presettings for the feature so you only call setInspectionDrivingSpeed when you want to.

The message() function is really handy for testing stuff like this.

You can use it to do some basic debugging. In this case - you can use something like this to determine the value of the variable Part_Size:
message("The value of the variable Part_Size = " + Part_Size)

You might also want to put something like this.. to test your expression

if Part_Size=="101221"

message("Part Size == 101221 worked.")

endif

Take the following with a grain of salt, I might not have everything just right and I am pretty sure Eric will tell me what I said wrong in great detail. 😃

What you put would probably work in this case since your variable contains all numbers and PCM is not very strict about interpretation of what is a number, however you should keep in mind what kind variable you are working with.

Your variable is actually not a number, it is a character string. The following is generally better when working with a variable that might contain letters. Since if you try comparing 101228 and 101228a PCM needs to determine how it is making that decision.

inStr checks the first string to see if it contains the second string (optionally starting at the character given) - it returns the position it found the string or Zero if it did not find the string.

// check Part_Size for the string 101228 beginning at the start of the string..
if inStr(Part_Size,"101228") == 1
// the first 6 digits of the variable PartSize contains the value 101228
// if the value was 1012281 or 10122810122736587 this would still match
// because the first 6 characters of the

endif

// example of providing a place to start the search..
// the following would check the variable Part_Size for the string 228 beginning at the 4th character of the string..
if inStr(4,Part_Size,"228") == 1
// this should match if the 4th, 5th and 6th digits of the variable PartSize contains the value 228
// it wont care what the first three digits are.
endif
Link to comment
Share on other sites

No I wont. I not an a-hole just because, and you don't say anything thats wrong. 😃

(If I say something wrong I welcome corrections, It's a great way to learn.)

How ever, for what it worth. I do not agree that its better to use inStr() in general. And in this case it's very impossible that the variable Part_Size contain anything else then "101221", "101228" or "". I understand what you say, but when choosing from a inquire you have made your self. It feels over complicated. And the less code you have, the faster it goes, generally speaking. And since PCM is so fu#king slow, it matters. But you are not wrong.

Clark, stick with what you have. A friendly suggestion tought. Be consistent. If you use space in one expression, do so in all of them. Don't mix 1==1 or a="b" with 1 == 1 or a = "b". And when dealing with conditions, indentation makes it more readable. And easier for your self to follow whats going on. (It has no practical difference in PCM, It just makes it easier to read if its consistent in formatting.) But you are ofcource free to do as you wish 😃
Link to comment
Share on other sites

I was kidding about being corrected, I agree it is good to have someone that will point things out so you can learn from them.

I also agree inStr() should not always be used. It is often unnecessary and it can make the code harder to understand at a glance and from what you say I guess it is slower as well.

I was only trying to point out that it should be a decision to use it or not and not just happen without understanding what is going on. I did mention that the code would work as is, but my intent was really more to show the importance of handling the data correctly based on the data type than specifying it should 'always' be checked a certain way.

In this case as you say it is not a problem, the inputs are controlled in the list but if someone were to cut and paste the code as you have mentioned before, then they would wonder later why did this work here, but broke over here.
Link to comment
Share on other sites

Agree. 😃

My usual approach to make sure the type of data is as expected, is to send a boolean to it. Eg .isString or .isInteger etc. It works on features/characteristics as well, .isCurve etc..
Link to comment
Share on other sites

if Part_Size=="101221"
setInspectionDrivingSpeed(30)
else
setInspectionDrivingSpeed(250)
endif


This worked as planned, thanks again for the assistance.
Link to comment
Share on other sites

 Share

×
×
  • Create New...