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
 Copy cell to a different workbook
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ds755

57 Posts

Posted - 01/20/2017 :  09:02:44 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 2015 Sr2
Operating System: Windows 7 Professional Service Pack 1

Hello everyone,

I have a lot of workbooks, whose filename contains the elapsed time. Inside each workbook there is a cell (row 31, column 5) with an electric current value.

I am trying to write a script that processes all the workbooks within the folder and:

1. Creates a new workbook with 2 columns
2. Appends the time value from the filename to column A
3. Appends the current value to column B

The script works but has two issues:

1. It crashes (even though it works), producing the error message:

Undefined variable: MAX(
sheetname.GetToken(8,"_")$ string expression error!
TIME:failed to add variable to local stack!

2. It does not process the workbooks in the right order, and as a result, the data point for t=1 is between t=31 and t=32.



The script I have written is the following:


// Set up a summary workbook, name will be stored in bkname$ by default
newbook name:="Ion_vs_time" option:=lsname;
wks.colwidth = 8;// set all col width to 8

Col(A)[L]$="Time";
Col(A)[U]$="Minutes";
Col(B)[L]$="Ion";
Col(B)[U]$="A";
int i = 1;

doc -ef LB { // loop over all workbooks in folder
//double Ion = max(col(E));
sheetname$=wks.longname$; //get the name of worksheet
string time$=sheetname.GetToken(8,"_")$; // get the string No8, which shows the time in minutes
int t = %(time$); // convert string to integer

range rap = [%H];

range r = %(rap)!Col(E); // origin range for Ion values

range dest1=[Ionvstime]1!wcol(1); // destination range for time values
range dest2=[Ionvstime]1!wcol(2); // destination range for Ion values

dest1[i]=t;
dest2[i]=r[31];

i=i+1;
}


I would appreciate any help in resolving these issues.

Edited by - ds755 on 01/20/2017 11:57:31 AM

Hideo Fujii

USA
1582 Posts

Posted - 01/20/2017 :  4:34:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi ds755,

Sorry for just replying only after glancing your code... Your following two lines have nested ranges:
range rap = [%H];
range r = %(rap)!Col(E);
Did you simply want to write:
range r=[%H]!Col(E);
or
string raps=%H;
range r=[%(raps$)]!col(E);
??

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 01/20/2017 4:36:05 PM
Go to Top of Page

ds755

57 Posts

Posted - 01/21/2017 :  01:00:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hideo,

I wanted to write:

range r=[%H]!Col(E);
Go to Top of Page

ds755

57 Posts

Posted - 01/23/2017 :  10:34:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Any ideas anyone?
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 01/23/2017 :  5:09:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi ds755、

By the following sentence, are you sure that you actually want the long name of the worksheet instead of the
sheet label which is in the tab in the workbook? The longname of the sheet is only shown when you put the
cursor on the tab (or in Name and Comments dialog):
sheetname$=wks.longname$; //get the name of worksheet

If you want to obtain the sheet name in the tab, you should use the following, istead:
sheetname$=layer.name$; //get the worksheet name in the tab

Could you please check?

--Hideo Fujii
OriginLab
Go to Top of Page

ds755

57 Posts

Posted - 01/24/2017 :  08:51:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hideo,

Yes, I actually want the long name of the worksheet, not the sheet label. The sheet label is a truncated version of the long name.

In any case, the problem is somewhere else.
Go to Top of Page

ds755

57 Posts

Posted - 01/24/2017 :  11:25:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
OK, I think I know why the program is crashing.

The newly created workbook Ion_vs_time is processed by the loop doc -ef LB. Since it does not have a longname, the command sheetname$=wks.longname$; assigns a blank entry to sheetname$, and the following command time$=sheetname.GetToken(8,"_")$; crashes, finding no 8th field to assign to time$.

Now, of course, I don't know how to solve this issue.

That also doesn't explain the second issue. Why does the program not process the workbooks in order? How does doc -ef LB choose which workbook to process first?

Edited by - ds755 on 01/25/2017 06:32:55 AM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 01/27/2017 :  9:07:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
So you need to use sheet longname? Why not just sheet name which is wks.name$

CP
Go to Top of Page

ds755

57 Posts

Posted - 01/30/2017 :  06:08:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cpyang

So you need to use sheet longname? Why not just sheet name which is wks.name$

CP




Hi cpyang,

If I use wks.name$ the GetToken function fails, as there is no field No8.
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