586,094 active members*
4,070 visitors online*
Register for free
Login
IndustryArena Forum > Machine Controllers Software and Solutions > CamSoft Products > How to do 2 "IF" statements on the same line?
Results 1 to 15 of 15
  1. #1
    Join Date
    Nov 2004
    Posts
    446

    How to do 2 "IF" statements on the same line?

    How do I put these 2 on the same line? They are to be run inside an Mcode.

    !IF \21=GET STAGE 1 THEN[GetStage1]
    !IF \21=GET STAGE 2 THEN[GetStage2]

    Nothing I do seems to work.. ELSEIF, ELSE IF, ORIF, OR IF, bla bla bla..

    When I put them on the same line, only the first IF statement will run... I can not get the 2nd one to work..
    They work fine if they are on different lines.

    Thanks for the help with all my quesitons..
    Murphy

  2. #2
    Join Date
    Mar 2005
    Posts
    116
    Quote Originally Posted by murphy625
    How do I put these 2 on the same line? They are to be run inside an Mcode.

    !IF \21=GET STAGE 1 THEN[GetStage1]
    !IF \21=GET STAGE 2 THEN[GetStage2]

    Nothing I do seems to work.. ELSEIF, ELSE IF, ORIF, OR IF, bla bla bla..
    It is not possible as far as I know since resolution for the first "then" is [GetStage1] and you can't have two resolutions at the same time. You have to do it with "else" and it needs a new line and an "end if"

    And if I'm wrong, just forget it.

    Yoram

  3. #3
    Join Date
    Mar 2004
    Posts
    761
    Use Select Case rather then If statments:

    SELECT CASE V21
    CASE GET_STAGE_1
    GetStage1
    CASE GET_STAGE_2
    GetStage2
    CASE ELSE

    END SELECT

  4. #4
    Join Date
    Mar 2004
    Posts
    60
    I agree with Yoram,
    !IF \21=GET STAGE 1 THEN[GetStage1] <---ends
    !IF \21=GET STAGE 2 THEN[GetStage2] <---ends
    if 21 is "GET STAGE 1" then is "true" so it assigns a certain value to memory, when it executes the next line the first result is cleared from memory since you are refering to the same "21" and writes no value to memory or might retain original value since is "false"

    Is all about logic, I do not know Mcode but most programing languages all abide by the same rules. I know a little Visual basic and I do alot of functions in excel. What you are trying to do is a "nested statement" (two logical checks on the same line)....you need to connect the two.


    my guess would be something like this:
    !IF \21=GET STAGE 1 THEN[GetStage1],!ELSEIF \21=GET STAGE 2 THEN[GetStage2]
    !END IF

    3 nested checks:

    !IF \21=GET STAGE 1 THEN[GetStage1],!ELSEIF \21=GET STAGE 2 THEN[GetStage2],!ELSEIF \21=GET STAGE 3 THEN[GetStage3]
    !END IF

    I used a comma to connect the two statements I am positive is wrong. take a look at other Mcodes that have two or more checks and see how they are connected.

    If your only two choices are stage 1 and stage 2 then I would simplify by using one check that would satisfy a true or false
    if is true then this, if is not then this
    Maybe:
    !IF \21=GET STAGE 1 THEN[GetStage1] !ELSE \[GetStage2]
    !END IF

    Again I dont know Mcode language however you must think "logic", in other words computers are dumb and only do what they are told, try to think like a computer "what are you telling me to do?"

    funny note:
    I took a C++ programing course. The most fun day was when the instructor asked us to write instructions on how to make a peanut butter and jelly sandwich, simple huh? He later broke out a bag of bread , jelly and peanut butter and had the students follow other students instructions and try to make the sandwich. Needless to say is hard to make a sandwich with a jelly jar, a peanut butter jar, two lids, a knife, a piece of bread, and a bag of bread all in your hands since who wrote the instructions never said to place these items down.

  5. #5
    Join Date
    Dec 2003
    Posts
    24221
    Quote Originally Posted by Cyclone
    funny note:
    I took a C++ programing course. The most fun day was when the instructor asked us to write instructions on how to make a peanut butter and jelly sandwich, simple huh? He later broke out a bag of bread , jelly and peanut butter and had the students follow other students instructions and try to make the sandwich. Needless to say is hard to make a sandwich with a jelly jar, a peanut butter jar, two lids, a knife, a pice of bread, and a bag of bread all in your hands since who wrote the instructions never said to place these items down.
    In a similar light vein, I remember way back an Electronic instructor's class came to mid-term break, instead of setting a test, asked all students to solve a problem his wife had in driving her car into their garage, the car was barely shorter than the length of the garage and she would end up bumping the end wall, the instructor was afraid that in the end the wall would suffer and repairs would be needed, so he asked all students that over the break they design a device that would indicate to his wife when her car was at the right position.
    Most students came up with varying degrees of electronic complexity, and all would have probally done the trick, but the one that won was the simplest solution.
    The winner suggested hanging a tennis ball on a string from the rafter that just contacted the windshield just in front of the driver side.
    Al
    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.

  6. #6
    Join Date
    Nov 2004
    Posts
    446
    To all posts above..

    So I stumped you guys???????

    Actually, I have to check \21 against 10 different possibilities in Mcode2 and then later in the same Mcode2 I have to check another 12 possibilities again
    I am pretty good with VB but there is no ELSE function in the Camsoft interface..
    And there is no SELECT CASE function either....

    Anyone have any other ideas???

    Murphy

  7. #7
    Join Date
    Jun 2004
    Posts
    487
    Hello. I'm not familiar with the interpreter you're using but, are you sure you can use a variable names with spaces in them? as in "get stage 1" as opposed to getstage1?

    What's wrong with WayneHill's suggestion?

    JR

  8. #8
    Join Date
    Mar 2004
    Posts
    761
    Quote Originally Posted by murphy625
    T
    And there is no SELECT CASE function either....
    Not VB? Camsoft??
    Oops

  9. #9
    Join Date
    Nov 2004
    Posts
    446
    Quote Originally Posted by JRoque
    Hello. I'm not familiar with the interpreter you're using but, are you sure you can use a variable names with spaces in them? as in "get stage 1" as opposed to getstage1?

    What's wrong with WayneHill's suggestion?

    JR
    There is no CaseSelect in my camsoft programming code.. I am familiar with it from programming in Visual Basic but this tool is not available to me this time.

    Spaces are ok it seems because most of my code is working.. My problem relates the the fact that my code is limited to 100 lines so if I put things on seperate lines, I am going to run short and not be able to finish it.. (this is a camsoft limitation)

    Hmm..
    Murphy

  10. #10
    Join Date
    Jun 2004
    Posts
    487
    Would adding a ; or : after the first IF..THEN statement work?

    !IF \21=GET STAGE 1 THEN[GetStage1]:!IF \21=GET STAGE 2 THEN[GetStage2]

    JR

  11. #11
    Join Date
    Nov 2004
    Posts
    446
    Quote Originally Posted by JRoque
    Would adding a ; or : after the first IF..THEN statement work?

    !IF \21=GET STAGE 1 THEN[GetStage1]:!IF \21=GET STAGE 2 THEN[GetStage2]

    JR
    Nope.. Tried it..
    [GetStage1]:IF \21=GET STAGE 2 THEN
    [GetStage1];IF \21=GET STAGE 2 THEN
    [GetStage1] ELSEIF \21=GET STAGE 2 THEN
    [GetStage1] ELSE IF \21=GET STAGE 2 THEN
    [GetStage1]OR IF \21=GET STAGE 2 THEN

    It seems as though the camsoft coding will only let me test for 1 item per line..

    I can however do a THENIF statement but that only works for both conditions holding true.

    Any other ideas??
    Im stummped..
    Placed a call to camsoft but got no reply.

    Murphy

  12. #12
    Join Date
    Mar 2004
    Posts
    36
    MurphiesLog StarDate 2005

    You can only perform the following statements:
    IF
    THENIF

    But you can also perform loops as you saw in my FILEREAD logic. CamSoft helped me with that.

    You can perform quite a bit a stuff with these two using MCODES, GCODES, MACROS and INPUTIO files.

    CamSoft has a very helpful front office and I always got a fast response, actually most of the time I get right through to support or a call back within the hour.

  13. #13
    Join Date
    Nov 2004
    Posts
    446
    Quote Originally Posted by intrusion
    MurphiesLog StarDate 2005

    You can only perform the following statements:
    IF
    THENIF

    But you can also perform loops as you saw in my FILEREAD logic. CamSoft helped me with that.

    You can perform quite a bit a stuff with these two using MCODES, GCODES, MACROS and INPUTIO files.

    CamSoft has a very helpful front office and I always got a fast response, actually most of the time I get right through to support or a call back within the hour.
    Was that a polite way of telling me I ask to many questions?? LOL

    I wish there was a case select or an "OR" statement.. hmmm.. Not so bad until you come up with a big complex system with lots of things going on.. That 100 line maximum is killing me because I can not daisy chain two IF statements on the same line..

    Any tips?
    Thanks Intrusion..

    Murphy

  14. #14
    Join Date
    Mar 2004
    Posts
    36
    MurphiesLog StarDate 2005

    100 lines is pretty long and there are neater ways to write logic in CamSoft. You can call macros and unlimted nested macros from what I am told.

    You should create some macros and call them from your MCODE. You can have a seperate macro for each series of things that you need to check. When the macro is finished the logic flow will return back to where it branched off from. This way you have no limitations :cheers:

    Example:
    IFbla.bla.blaTHEN[CALL MACRO1]
    IFbla.bla.blaTHEN[CALL MACRO2]
    IFbla.bla.blaTHEN[CALL MACRO3]

    After each macro is finished then next IF statement will execute if you need it too.

    Unleash your logic :bat:

  15. #15
    Join Date
    Nov 2004
    Posts
    446
    oH YA!.. My macro.fil is up to around 40K in size with about 100 of those buggers now.

    This camsoft is very compartmentalized and its just taking me a bit to get out of the Visual Basic ways.

    Thanks for the tip !!!
    Murphy

Similar Threads

  1. single line fonts?
    By balsaman in forum Uncategorised CAM Discussion
    Replies: 12
    Last Post: 02-18-2006, 06:51 PM
  2. Single Line Fonts
    By A. Shuford in forum Uncategorised CAM Discussion
    Replies: 1
    Last Post: 11-14-2004, 03:21 PM
  3. Tool tables
    By Nimrod in forum Mastercam
    Replies: 4
    Last Post: 11-24-2003, 09:31 PM
  4. Please help me out with the line : G450 CFTCP
    By BanglaTech in forum Uncategorised CAM Discussion
    Replies: 0
    Last Post: 10-25-2003, 07:08 AM
  5. Line weight
    By JOE65 in forum Autodesk
    Replies: 4
    Last Post: 05-21-2003, 05:31 AM

Posting Permissions

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