Ruby Code - If Equal to Text String Issue


ComputerMaster86
 Share

Recommended Posts

For some reason I can't seem to get this to work.  I have a macro that I use in conjunction with shelves that creates a SKEW code.  Shelves are being used to represent steel panels for the purpose of generating steel layout drawings.  This skew code identifies the steel panel item in QuickBooks, when we go to create an estimate for the customer.  I want to be able to type in a color into text box labeled Code under the shelves dialogue box.  Based on whatever value (color) I type in the text box labeled Code, I want the value replaced with a color code when the macro formulates the skew.  The skew is displayed in the code column of a cabinet schedule I use as a steel panel schedule.

 

A 6'-9" long shelve with Burgundy as the value for "Code" would spit me  out a skew code "G06/09J1".  My macro works except for replacing the color with a color code.  I think it's an issue with the part of the code I included below.

 

 

color = owner.component_code

 

if color == "Burgundy"

 

color = "J1"

 

elseif color == "Black"

 

color = "D1"

 

elseif color == "Blue"

 

color = "F1"

 

elseif color == "Burnished Slate"

 

color = "BS1"

 

elseif color == "Brown"

 

color = "B1"

 

elseif color == "Bright White"

 

color = "U1"

 

elseif color == "White"

 

color = "M1"

 

else

 

color = "???"

Link to comment
Share on other sites

Lance,

Put your color code in the OIP for the shelf.  That's what owner.component_code uses to get the "color".  This is completely independent of any actual color in the shelf since there's no attribute for the color names.  You could even create a custom field "color_code" which could be used instead of the "component_code" but that's only if you want.

 

IAE, the actual object color would be irrelevant except for graphic representation. 

Link to comment
Share on other sites

This generates the color code correctly based on text entry in the code field. I'd think you want to concatinate it with the rest elsewhere? (biggest problem was you had elseif instead of elsif) OR use a case as Eric suggests-easier

color =  owner.component_code

sku=' '
if
color == 'Burgundy'
then  'J1'

elsif
color == 'Black'
 then  'D1'

 elsif
color == 'Blue'
 then  'F1'

 elsif
color == 'Burnished Slate'
then  'BS1'

elsif
color == 'Brown'
then  'B1'

elsif
color == 'Bright White'
then  'U1'

elsif
color == 'White'
then  'M1'

else  '???'
end

 

 

OIP fields color sku.png

Link to comment
Share on other sites

Note that you can then use the Shelf Label to display the color by typing %component_code% in the Label.

 

Another options would be to use a custom field

  • SKEW_Code

and enter the "J1", "D1", "G3" etc directly thus eliminating the need to convert from colors to codes.

 

  • Upvote 1
Link to comment
Share on other sites

 

1 hour ago, ComputerMaster86 said:

The skew is displayed in the code column of a cabinet schedule I use as a steel panel schedule.

You definitely need a custom field to use in the schedule since the "Code" column is hard coded to use the value in that OIP field.  With a custom field, you can put macros in that will display what you want for the SKEW in the schedule.  If you don't want to create a custom field then use the Comment field to put your macro(s) in and rename that column in the schedule.

  • Upvote 1
Link to comment
Share on other sites

I mis-spoke myself.  The skew is placed in the description column of the cabinet schedule.  The box that is title code is where I am typing a color.  The actual color of the shelf doesn't matter.  The box titled description has the macro that formulates my skew.  Anyways Mark figured out my issue I had miss-typed elseif for elsif.  I seem to do that very now and then. Thank you all for your input and help.

 

42 minutes ago, MarkMc said:

This generates the color code correctly based on text entry in the code field. I'd think you want to concatinate it with the rest elsewhere? (biggest problem was you had elseif instead of elsif) OR use a case as Eric suggests-easier

 

Link to comment
Share on other sites

I use Notepad++ as my editor of choice.  By setting the language to "Ruby" I get things like that in color.  So when I see:

  • elsif I know it's correct
  • elseif I know it isn't correct.

There are many formatting and spelling variations and having an editor that points out problems can be very helpful.  After editing in Notepad++ I simply copy/paste into Chief's Ruby Editor and save.

  • Upvote 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share