Thank you!

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
pierre

Thank you!

Post by pierre »

Excellent functions!
setvalue, getvalue, and getvaluealpha
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Thank you!

Post by Gregory Martin »

Yeah, I've definitely wanted a setvalue function for a while, particularly for using with the userbar. I originally was going to name it assign, but it ended up as setvalue.
Guest

Re: Thank you!

Post by Guest »

I like these functions and awant more explications about it.

In the examples given by greg I have that:

// instead of writing...
SEX = 2;
// you can write...
setvalue("SEX",2);

more generally, we can do:
setvalue(getsymbol(),missing);

I understand that if I don't have the name of the variable I want to assign to, I can use another one which the value is the name of variable I want to assign to.
According to this understanding, I tried the following example:

string a_setvalue = "a_setvalue1", a_setvalue1;
to assign a value to a_setvalue1, I think have to way:

a_setvalue1 = "n_setvalue";
or

setvalue(a_setvalue,"n_setvalue"); since the value of a_setvalue is "a_setvalue1".
When I use the last syntax I have "" (blank) as result. Where is the problem ?

I also have the problem with getvalue and getvaluealpha

string a_setvalue2 = "Test_getvaluealpha";
numeric n_setvalue1 = 5;

when I use errmsg to display the values of my variables in the following syntax:
errmsg("a_setvalue2 = %s et n_setvalue1 = %d",getvaluealpha(a_setvalue2),getvalue("n_setvalue1"));

I see that getvaluealpha(a_setvalue2) gives ""(blank) and getvalue("n_setvalue1") gives default.

What is wrong in these syntaxes ?

Thank you for any help, I greatly need to use those functions.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Thank you!

Post by Gregory Martin »

The idea behind your syntax is correct, but I should have made it clearer when I gave the examples that you can only use these functions to assign to items in your dictionary. The idea with these functions is that you're going to want to do something to the field that you're on, but you don't know example what field you're on, so you use setvalue along with the getsymbol function. Here's another example that allows us to assign 0 to the current field that we're on, regardless of the field (as long as it's numeric).
function OnKey(keystroke)

    
if keystroke = 3065 then // they pressed Control + Shift + A
        setvalue(getsymbol(),0);
        
errmsg("Assigned current field to 0...");
    
    
else
        OnKey = keystroke;
    
    
endif;

end;


Last bumped by Anonymous on June 27th, 2014, 9:51 am.
Post Reply