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
 filename as column label script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

masterd

Australia
Posts

Posted - 08/25/2005 :  01:07:45 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): Pro 7.5 SR4
Operating System: XP

Hello there,

I import an awful lot of ASCII files into Origin at the same time, so I have set up an import wizard with the following script to set filename as column label on all y columns:

%a = Doc.DropFileName$; // Get Path + File Name

// Need to extract just File Name from this string

ilen = %[ %a ]; // get length of string

for( ii = ilen; ii >= 1; ii-- ) // read from right end and find the "\" character

{

%b = %[ %a, ii : ii ];

if( %b == "\" ) break; // if "\" found, exit from loop

};

%b = %[ %a , ii + 1 : ilen ]; // get part of string to right of "\" found

wks.col$( wks.ncols ).label$ = %b; // assign extracted filename to column label

wks.labels(); // turn on display of label


It works fine except one small thing. it includes a file extension (.libs) in each label and I dont need file ext as some of the filenames are quiet long anyway. Is it possible to modify the script not to include file extension when setting column labels?

While we are at it, some filenames contain underscores("_"), so is it possible to replace underscores with a space?

Thanks in advance,

Darko


Mike Buess

USA
3037 Posts

Posted - 08/25/2005 :  07:38:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Use this to strip the file extension.... %A=%[%A,'.'];

LabTalk can't do character replacement so you'd have to examine and manipulate the string character by character. Much easier to use this simple OC function...

string replace_withSpace(string str)
{
str.Replace('_',' ');
return str;
}

Use it in you scripts like this... %A=replace_withSpace(%A)$;

...Turns out there is a relatively simple LT method after all,

%A=one_two_three;
%B="";
for(i=1;i>0;i++) {
%T=%[%A,#i,_]; if(%T=="") break;
%B=%B %T;
};
%B=;
one two three

So, take your pick.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 08/25/2005 07:57:41 AM
Go to Top of Page

masterd

Australia
Posts

Posted - 08/25/2005 :  10:54:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot Mike!

It took a bit of fiddling but now its all smooth sailing, just like hot knife through the butter!

For some reason I could not get (%A=replace_withSpace(%A)$;) working but that last LT method certainly did solve my picky problem.

Extension stripping works just as it should.

Now I can show off at uni and convert all those loyal Excel workmates to Origin loyals. lol

Thanks again

Darko

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