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
 Origin Forum
 Join String Operation in "Set columns"
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

premiumxy

17 Posts

Posted - 09/15/2010 :  04:12:40 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Dear all,

I have a - to my opinion - simple problem: I have two columns, containing numbers. I want to combine these numbers with a string operation in a third column (and later use this column as a label-column).

Example:

ColA ColB ColC
1 5 15

How can I (1) convert numbers to string, and (2) join these strings?

Penn

China
644 Posts

Posted - 09/15/2010 :  05:34:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

About how to convert numeric to string, please refer to this page. For your case, you need a loop structure to go through all the rows. You can put the following script in the Before Formula Scripts panel of the Set Values dialog and have a try.

for(ii=1; ii<=wks.maxrows; ii++)
{
	string str1$ = $(col(a)[$(ii)]);
	string str2$ = $(col(b)[$(ii)]);
	col(c)[$(ii)]$ = str1$+str2$;
}


Penn
Go to Top of Page

premiumxy

17 Posts

Posted - 09/15/2010 :  06:52:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much, Penn. Problem solved to 100%! :-)

May I still ask two little things (giving me a link for further reading is also ok), since I am new to LabTalk:

(1) Why do you use $(ii) instead of just ii to reference to the variable ii?
(2) I tried to change the type of the column to "label" via
wks.col3.type = 5;
It only worked for "col3" but not for col(c). In your example, col(c) did also work. Why?

Thanks a lot,
Stefan
Go to Top of Page

Penn

China
644 Posts

Posted - 09/15/2010 :  10:52:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Stefan,

For 1st question:
The $() notation is used for numeric to string conversion. This notation evaluates the given expression at run-time, converts the result to a numeric string, and then substitutes the string for itself. Please refer to substitution notation.

For 2nd question:
This is about how to access column object. Please refer to this page.

Penn
Go to Top of Page

premiumxy

17 Posts

Posted - 09/16/2010 :  11:44:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot!
Go to Top of Page

Penn

China
644 Posts

Posted - 09/17/2010 :  12:10:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Stefan,

Actually, you don't need to use $() notation for ii from Origin 8. So you can just use the script like:

for(ii=1; ii<=wks.maxrows; ii++)
{
	string str1$ = $(col(a)[ii]);
	string str2$ = $(col(b)[ii]);
	col(c)[ii]$ = str1$+str2$;
}


Penn
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