Help referencing strconstant

sjr51
Posts: 275
Joined: 2012-12-16
Location: United Kingdom

Hello all,

I'm trying to reference a strconstant and can't get it to work. I must be missing something simple. Outside of my function I have:

StrConstant SRON_1 = "0x4477aa;"
StrConstant SRON_2 = "0x4477aa; 0xcc6677;"
StrConstant SRON_3 = "0x4477aa; 0xddcc77; 0xcc6677;"
StrConstant SRON_4 = "0x4477aa; 0x117733; 0xddcc77; 0xcc6677;"
//snip

and so on.

In my function I want to pick one of these palette lists to use and then go on to pick and calculate a colour.

//snip
String palettepick= "SRON_" + num2str(cond)
SVAR pal= palettepick
//then in a loop lower down
color=str2num(StringFromList(i-1,pal))

I then calculate the 16 bit RGB from the hex color. The code all runs except that it just takes the last StrConstant in the list, i.e. even though cond=2 it will take SRON_12. So the SVAR pal= palettepick seems to not work the way I think it should. I've searched the help etc. and couldn't find a solution. Is it possible to determine this programmatically or do StrConstants have to be addressed by the user?


[ last edited August 20, 2015 - 05:24 ]
jtigor
Posts: 405
Joined: 2007-09-04
Location: United States

I don't think that is a valid way to access a constant. That is, you can't form a constant name using a string variable.

Something like this will work...

StrConstant sC1 = "constant_1"
StrConstant sC2 = "constant_2"
StrConstant sC3 = "constant_3"
 
Function TestConstant(vIndex)
	Variable vIndex
	String sCon
 
	if( vIndex == 1 )
		sCon = sC1
	elseif( vIndex == 2)
		sCon = sC2
	elseif( vIndex == 3)
		sCon = sC3
	endif
 
	print sCon
End


sjr51
Posts: 275
Joined: 2012-12-16
Location: United Kingdom

Thank you! It's working now!


Back to top