DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

gosub

Started by wgwade, May 15, 2011, 12:53:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wgwade

Can you use a GOSUB in a FOR NEXT loop in Design cad macros ?.
FOR j = 1 to 10
      GOSUB 200
NEXT j
END

200:
        a=4
        b=5
RETURN
Thank you, Bill.

Lar

Yes you can!

One great thing about macros is that you can test something by just running it.

I assume the code you wrote is just a simple example because it doesn't make good use of gosub/return, since it will always come back with the same results. In my example below I added some code to get varied results and inserted a message to can get feedback on what's happening. Also, it's always good to put code in a code box by clicking the # button (above) and pasting the code in between the sets of square brackets. Otherwise some of the macro code may be read as forum code and you get smileys or strikethroughs or something.


FOR j = 1 to 10
      GOSUB 200
message "At j=",j, "a=",a,", b=",b                          'simpler message
'message "At j=",j, "a=(4+j)=",a,", b=(5-j)=",b      'more complex but more info
NEXT j
END

200:
        a=4+j
        b=5-j
RETURN