String to color number

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

String to color number

Postby arjfca » 09 Jul 2012

Hello

Is there a command to take a variable string value ("Blue") to be use in a color definition.

Martin
Last edited by arjfca on 10 Jul 2012, edited 1 time in total.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: String to color numver

Postby JoshM » 09 Jul 2012

Is there a command to take a variable string value ("Blue") to be use in a color definition.
Not that I'm aware of.

Btw, the reserved word Blue is a constant for the RGB value for the colour blue. Little tip: make a function that has the colour name as input, then uses a switch statement to return the RGB colour for that name.

As a starting point (needs to be tested and expanded on), the function named "NameToColour":

Code: Select all

Inputs:
ColourName(StringSimple);

Variables:
colourInLowerString(""); // not case-sensitive anymore

colourInLowerString = LowerStr(ColourName);

switch (colourInLowerString ) begin

case "blue":
NameToColour = RGB(0, 0, 255);

case "black":
NameToColour = RGB(0, 0, 0);

end;
You can then call this with:

Code: Select all

SetPlotColor(1, NameToColour("black"));
Just expand the switch statement with all colours you'd like. :)

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: String to color numver

Postby arjfca » 09 Jul 2012

OK, I see Josh

If I recall, there is 17 reserved word for color, I will need to reference each of them. Dull to do, but possible.

I will post the function on the forum

Martin :)

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: String to color numver

Postby TJ » 09 Jul 2012

Hello

Is there a command to take a variable string value ("Blue") to be use in a color definition.

Martin

Code: Select all

if mystring = "Blue" then color = blue;
if mystring = "Red" then color = red;
if mystring = "Green" then color = green;

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: String to color numver

Postby JoshM » 09 Jul 2012

If I recall, there is 17 reserved word for color, I will need to reference each of them. Dull to do, but possible.
Yes, they're listed here. Btw, there are a lot of other pretty colours (see here) that you could use in case you want more than one type of green or blue.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: String to color numver

Postby arjfca » 09 Jul 2012

Did post a simple function to do it

Thanks JoshM

viewtopic.php?f=5&t=10600#p51916

Martin


Return to “MultiCharts”