No Macro Assignment in If Statement?

Started by JakeL, November 22, 2024, 08:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JakeL

I feel like I'm doing something wrong here, or I'm just expecting the Fanuc Macro language to be better than it is.

QuoteIF[1 EQ 1] #501=2

I'm on a Fanuc 31i control. Running the above line causes an if statement format error to be thrown. Can I not assign a value to a macro variable in an if statement?

QuoteIF[1 EQ 1] GOTO5
#502=45
N5
#501=2
N5

This code runs as expected no errors. It correctly updates #501 to 2 and leaves #502 alone. Do I have to use GOTO with an if statement?

kdg

It's been a long time since I coded macro b, but...

I believe you need a then statement, IF[1 EQ 1] THEN #501=2
Like Like x 1 View List

JakeL

Quote from: kdg on November 22, 2024, 09:08 AMIt's been a long time since I coded macro b, but...

I believe you need a then statement, IF[1 EQ 1] THEN #501=2

Nailed it, thank you!

Follow up question, is there a way to have more than one command inside an if statement? The following code logically would set #501 to 45 and then jump to the N5. But the machine alarms out because it doesn't like having two commands on on the one if line.

QuoteIF[1 EQ 1] THEN #501=2 GOTO5
#501=45
N5

riverhunter

#3
If condition #1 is met you would need to add ELSE

JakeL

Quote from: riverhunter on November 22, 2024, 10:04 AMIf condition #1 is met you would need to add ELSE

Sorry I wasn't clear. I would like to do both commands if the condition is met.

IF[1 EQ 1] THEN #501=2 GOTO5
#501=45
N5

This is what I'm trying to do: if 1=1 I want #501 set to 2 AND jump to N5

JParis

#5
Try this

IF[1 EQ 1]GOTO5
GOTO6

N5
#501=2
GOTO7
N6
#502=45

N7


The order could change depending on what you're overall trying to do

Fanuc Macro B is very powerful,  it also has limitations on how you address things...


CNCAppsJames

I'm used to seeing;
IF[#...EQ...]....
WHILE[#...EQ...]...

IF#[...EQ...]...
WHILE#[...EQ...]...
"That bill for your 80's experience...yeah, it's coming due. Soon." Author Unknown

Inventor Pro 2026 - CAD
CAMplete TruePath 2026 - CAV and Post Processing
Fusion360 and Mastercam 2026 - CAM

JakeL

Quote from: JParis on November 22, 2024, 10:47 AMTry this

IF[1 EQ 1]GOTO5
GOTO6

N5
#501=2
GOTO7
N6
#502=45

N7


The order could change depending on what you're overall trying to do

Fanuc Macro B is very powerful,  it also has limitations on how you address things...


That's how I have it setup right now. Was trying to simplify it if I could cause I'm sure in a few years I'm gonna have to look back at this and have to figure it out again. If that's the best way then that's how it'll be.
Like Like x 2 View List

JakeL

Quote from: CNCAppsJames on November 22, 2024, 10:47 AMI'm used to seeing;
IF[#...EQ...]....
WHILE[#...EQ...]...

IF#[...EQ...]...
WHILE#[...EQ...]...

It's funny, it took me a few hours to throw together this little project I'm working on. Would have probably taken a few days if I didn't have your "Custom Macro B Quick Reference" sheet.

I'm used to coding in C++, same concepts apply here but different syntax. It's soooooooo nice to have this sheet to see the syntax, and not have to look up all the macro variables I need. Huge thank you James!  :cheers:
Like Like x 1 View List

CNCAppsJames

Believe it or not, I refer to it quite often. I don't have most of it memorized contrary to popular belief. :rofl:
Like Like x 1 Funny Funny x 1 View List
"That bill for your 80's experience...yeah, it's coming due. Soon." Author Unknown

Inventor Pro 2026 - CAD
CAMplete TruePath 2026 - CAV and Post Processing
Fusion360 and Mastercam 2026 - CAM

Tryon

I've just started learning about ENDIF.  I think I have it right.  There may be a parameter they needs flipped to enable it.   


IF[1 EQ 1] THEN #501=2
#501=45
ENDIF


Flycut

Please forgive me for being slow but why IF[1 EQ 1] THEN #501=2 and not just #501=2
Last I checked 1 always =1

JakeL

Quote from: Tryon on November 22, 2024, 04:48 PMI've just started learning about ENDIF.  I think I have it right.  There may be a parameter they needs flipped to enable it.   


IF[1 EQ 1] THEN #501=2
#501=45
ENDIF



That looks like it would do the job. My only concern is this job may end up running on a 30i control. Not sure the IF THEN ... ENDIF statement works on the 30i and I don't have the control to test right now.


JakeL

Quote from: Flycut on November 25, 2024, 05:07 AMPlease forgive me for being slow but why IF[1 EQ 1] THEN #501=2 and not just #501=2
Last I checked 1 always =1


The actual logic in the code is IF[#511 EQ 1] but I didn't want to have to define #511 for the example. I didn't care about the actual comparison of the if statement, just how it handles the result.

I agree, as far as I know 1 always =1
Like Like x 1 View List

gms1

I do alot of if/or checks with my probing like this:

IF[[#2209GT.2]OR[#2209LT-.2]]GOTO3000