The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Naming a variable with another variable

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
couturier Posted - 11/11/2014 : 10:20:20 AM
Origin Ver. and Service Release (Select Help-->About Origin): 2015
Operating System: 7 64bit

In LT, the following script is possible:
string str$=Test;
double TestVar=1;
%(str$)Var+=4; // TestVar=5

Is it possible to do something similar in OC ?

Thanks

5   L A T E S T    R E P L I E S    (Newest First)
Castiel Posted - 11/12/2014 : 07:41:31 AM
quote:
Originally posted by couturier

Origin Ver. and Service Release (Select Help-->About Origin): 2015
Operating System: 7 64bit

In LT, the following script is possible:
string str$=Test;
double TestVar=1;
%(str$)Var+=4; // TestVar=5

Is it possible to do something similar in OC ?

Thanks





Have some variables defined and want to get one of them by its name?
int vrbs(const string& s)
{
    Tree t;
    t.PM25.nVal = 700;
    t.Population.nVal = 21150000;
    t.TimeZone.nVal = +8;
    
    TreeNode tn = t.GetNode(s);
    if(tn)
        return tn.nVal;
    
    return 0;
}

The variable can be an integer/double/string/vector...

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
cdrozdowski111 Posted - 11/12/2014 : 05:29:32 AM
One way to dynamically "create" scalar variables in C is to use vectors.

You would be dealing with integer indices in the vector rather than an alphanumeric name for each element, but it works and seems to be the suggested method when one searches on the subject of dynamic variable naming in those languages.
SeanMao Posted - 11/12/2014 : 05:00:38 AM
Hi,

Since OC follows the syntax from standard C Programming Language so the variable manipulation you have asked might not be supported by OC.

Regards!

Sean
couturier Posted - 11/12/2014 : 04:25:03 AM
Hi Sean,

thanks for your reply but this is not what I was trying to do.
I want to manipulate variables in OC, not LT.
SeanMao Posted - 11/12/2014 : 04:03:21 AM
Hi,

Can you try the OC script below:

void test_lt_var(string str)
{
	double dVal;
	string strVar = str + "Var";
	LT_get_var(strVar, &dVal);
	dVal += 4;
	LT_set_var(strVar, dVal);	
}



Then you can run the defined function as following:

double TestVar=1;
test_lt_var("Test");
TestVar=;


It simply calls some of LabTalk functions from OC.

Regards!

Sean

OriginLab Technical Service

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000