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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Naming a variable with another variable
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

couturier

France
291 Posts

Posted - 11/11/2014 :  10:20:20 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

SeanMao

China
288 Posts

Posted - 11/12/2014 :  04:03:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

couturier

France
291 Posts

Posted - 11/12/2014 :  04:25:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

SeanMao

China
288 Posts

Posted - 11/12/2014 :  05:00:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cdrozdowski111

USA
247 Posts

Posted - 11/12/2014 :  05:29:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

Castiel

343 Posts

Posted - 11/12/2014 :  07:41:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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...

妾+   午旦  妹罕妾  妾伊    用仇  妾/     岫ㄞ
 妾京用 仍巨  件 侈   件戶' 甘岫平   /欠  白岫妹
   併             艮          岫  奈 白   岫
                              岫
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000