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
 LabTalk Forum
 setting a variable to a cell value
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

MegW

USA
2 Posts

Posted - 06/25/2012 :  4:53:32 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):8.5
Operating System:XP
I have a worksheet that has dates in column A and corresponding data collection session identification numbers in column B. I want to use the date (collected from the user as a string variable called date$) to get the value of the corresponding session number in the same row of column B, and set a variable called "sess" equal to that cell value. Basically, sess = row(date$) of col B. (1) Can I do this without using any kind of extract function and (2) if so, what is the appropriate LabTalk syntax? I've tried about 50 variations.

Kathy_Wang

China
159 Posts

Posted - 06/26/2012 :  01:29:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You may create a string array of your column A and use the "Find" command to return to corresponding row index, and then use the row index to access corresponding cell in column B.

An example would be:

//Append the string variables in column A as a string array
StringArray aa;
range r1=col(1);
aa.Append(r1);
//Pop up a dialog to let user input a date.
getstring  (Type the date here);
//%B stores the user-input date as a string variable
string date$=%B;
//return to the row index of the matching date in string array
int nn = aa.Find(date$);
//return to the corresponding cell of col B, the variable type may need to change according to your data
double sess=col(2)[$(nn)];
sess=;


You might refer to the following two pages for more information and examples of the StringArray:Find and getstring command:

http://www.originlab.com/www/helponline/Origin/en/Programming/mergedProjects/LabTalk/LabTalk/StringArray_(object).html#Find

http://www.originlab.com/www/helponline/Origin/en/programming/mergedProjects/LabTalk/LabTalk/GetString_(command).html

Please note that the hyperlink might not work for direct clicking, then you will need to copy and paste the address into your browser, sorry for the inconvenience.

Kathy
Originlab

Edited by - Kathy_Wang on 06/26/2012 01:36:30 AM
Go to Top of Page

MegW

USA
2 Posts

Posted - 06/28/2012 :  11:20:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Kathy. I tried this code as well as several variations but cannot get it to work. I either get an error message that col2[nn] is an undefined variable (with nn being the number of the row in question, like 12), or I'm told that sess = --. Most of the variations I've tried involve specifically designating which worksheet of the open workbook I want to use. I've also tried having that worksheet active as I type the commands into the command line. Always one of those two results. I'll read more about these commands and see if I can figure out what's going on.

-Meg
Go to Top of Page

Kathy_Wang

China
159 Posts

Posted - 06/28/2012 :  9:06:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I'm not sure what lead to your problem, as when I tried the codes are working fine.

The error message "col2[nn] is an undefined variable" appears to me that instead of using "col(2)[$(nn)]", you were using the syntax "col2[nn]" somewhere, and this might be the problem.

Also sess=-- might indicate that nn returns to 0 value, i.e. no matching string is found.

I think you could first check this by yourself, if it's still not solved, please send your project file including the worksheet to tech support so we can investigate.

You could follow the instructions below to send your file.
http://www.originlab.com/index.aspx?go=Support&pid=752

Kathy
Originlab
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