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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 using variable in col()

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
RiverFalls Posted - 08/27/2019 : 5:50:21 PM
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:Win 10

We would like to use a variable in col() (as shown below in the script), but we cannot get it to work. How can we use a variable in this way?

Thank you,
Lowell

-----------------------------------------

range aa=%C;
%A = aa.lname$;

string CERSspectraBK$= Spectrum.txt;
string CERSspectraSHT$ = Results;
string PeaksBK$ = SplitSpectra;
string PeaksSHT$ = Results;

string fixedname$ = CheckPeaks;

int activecol = colnum(%C);
int nextcol = activecol+1;
int Spectracol = nextcol/2 +1;


plotxy iy:= [CERSspectraBK$]CERSspectraSHT$!(1,$(Spectracol)) ogl:=[<new template:=CheckPeaksGraph name:=CheckPeaks>]ogl:=[CheckPeaks] plot:=200;


int numPeaks = %([PeaksBK$]PeaksSHT$!col(3)[C]$);

//In the line above we would like to use the variable activecol instead of the value 3, like:
// int numPeaks = %([PeaksBK$]PeaksSHT$!col(activecol)[C]$);
//but this doesn't work.

type "activecol = $(activecol)";
type "numPeaks = $(numPeaks)";
type "%A";
for(int i = 1; i <= numPeaks; i++){
draw -c 1 -d 0 -l -v aa[i];
}
5   L A T E S T    R E P L I E S    (Newest First)
yuki_wu Posted - 08/29/2019 : 01:44:56 AM
Hi All,

Sorry that I wasn’t aware Lowell desired to use % with an embedded $. For now, it is not allowed the embedded use of % and $. Instead of the workaround that James mentioned, we can use string registers to avoid this:
int aa = 3;
%A = col($(aa))[L]$; 
int aa = %A

Regards,
Yuki

OriginLab
RiverFalls Posted - 08/28/2019 : 12:33:34 PM
James,
That worked exactly the way we want. Thank you!
Lowell
YimingChen Posted - 08/28/2019 : 12:27:04 PM
Hi,

Instead of using col(activecol), can you use wcol(activecol)? Thanks.
https://www.originlab.com/doc/LabTalk/ref/WCol-func

James
RiverFalls Posted - 08/28/2019 : 10:28:35 AM
We tried that already in each of the following forms:

int numPeaks = %([PeaksBK$]PeaksSHT$!col($(activecol))[C]$);

and

int j =3;
int numPeaks = %([PeaksBK$]PeaksSHT$!col( $(j))[C]$);

neither one works, which is why we are so confused!

Lowell

yuki_wu Posted - 08/27/2019 : 10:54:42 PM
Hi,

Use $ to convert numeric to string, for example:
int aa = 3;
col($(aa))[L]$ = "New Long Name" //Set long name for the 3rd column

Regards,
Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000