MikeJG Posted February 10, 2015 Share Posted February 10, 2015 Is it possible to have an if/else statement in a macro? What I would like to do is have a door label macro that will give me a different result based on whether it is a double door or not. (There are also a bunch of other applications for this that I'm thinking about). For instance, the way we label doors around here a 3-0 swing door would be "D30". However, as a double door it would be "2-D16". So the statement would be something like: If is_double_door = true then "2-D" width / 2 Else "D" width If it can be done, what would the syntax look like? Any help would be appreciated. Link to comment Share on other sites More sharing options...
Joe_Carrick Posted February 10, 2015 Share Posted February 10, 2015 Is it possible to have an if/else statement in a macro? What I would like to do is have a door label macro that will give me a different result based on whether it is a double door or not. (There are also a bunch of other applications for this that I'm thinking about). For instance, the way we label doors around here a 3-0 swing door would be "D30". However, as a double door it would be "2-D16". So the statement would be something like: If is_double_door = true then "2-D" width / 2 Else "D" width If it can be done, what would the syntax look like? Any help would be appreciated. case If is_double_door == "true" result = "2-D"+(width/2).to_s else result = "D"+width.to_s end result Link to comment Share on other sites More sharing options...
MikeJG Posted February 10, 2015 Author Share Posted February 10, 2015 Joe, Thanks again for your help! I'm getting an evaluation error. See below: Link to comment Share on other sites More sharing options...
Joe_Carrick Posted February 10, 2015 Share Posted February 10, 2015 Mike,try this: case when is_double_door == "true" result = "2-D"+(width/2).round.to_s else result = "D"+width.round.to_s end result "if" doesn't work within a "case". The proper syntax is "when" Of course for a 36" single door the above results in D36, not D30. Likewise a pair of doors totalling 36" would result in 2-D18 not 2-D16. To get the exact result you indicate would require using divmod(12) as per a previous exercise. like this: case when is_double_door == "true" w = (width/2).round.divmod(12) result = "2-D"+"#{w[0]}#{w[1].round}" else w = width.round.divmod(12) result = "D"+"#{w[0]}#{w[1].round}" end result Link to comment Share on other sites More sharing options...
MikeJG Posted February 11, 2015 Author Share Posted February 11, 2015 Joe, The result was coming out "D30" regardless.of whether it was a double door or not. I was determined to try to figure it out for myself, so I did some googling. It turns out I had to remove the quotes from around "true" on the 2nd line so it reads now: case when is_double_door == true w = (width/2).round.divmod(12) result = "2-D"+"#{w[0]}#{w[1].round}" else w = width.round.divmod(12) result = "D"+"#{w[0]}#{w[1].round}" end result Now it works! Thanks again for taking the time to help! Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now