View Full Version : How to do 2 "IF" statements on the same line?
murphy625 04-01-2005, 03:02 AM 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
TigerPilot 04-01-2005, 08:01 AM 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. :D
Yoram
WayneHill 04-01-2005, 08:39 AM Use Select Case rather then If statments:
SELECT CASE V21
CASE GET_STAGE_1
GetStage1
CASE GET_STAGE_2
GetStage2
CASE ELSE
END SELECT
Cyclone 04-01-2005, 09:18 AM 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.
Al_The_Man 04-01-2005, 10:11 AM 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 :)
murphy625 04-01-2005, 12:36 PM 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
JRoque 04-01-2005, 02:04 PM 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
WayneHill 04-01-2005, 02:32 PM T
And there is no SELECT CASE function either....
Not VB? Camsoft??
Oops :eek:
murphy625 04-01-2005, 02:52 PM 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
JRoque 04-01-2005, 03:02 PM 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
murphy625 04-01-2005, 03:42 PM 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
intrusion 04-01-2005, 04:46 PM 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.
murphy625 04-01-2005, 05:05 PM 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
intrusion 04-01-2005, 05:37 PM 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:
murphy625 04-01-2005, 07:28 PM 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
|
|