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
 Column Header

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
sebbey Posted - 06/19/2012 : 06:52:55 AM
Origin Ver.: 8.6.0G
Operating System: Windows 7 Professional

Hi Guys,

I'm trying to define a variable, which tells me in which column a certain longname header is positioned.

For example: I have a column with the longname header "Line_Point_No". Now I want to know which column number this Column has.

This is the script I use:

range rWb = !; // Use the active worksheet as a range
NumColumns = rWb.ncols; //get the number of columns in worksheet
NumColumns =;
167  //number of cols is 167

//search for longname header and save columnnumber in lineno$
int ii=0;							
for(ii=0; ii<=NumColumns; ii++)
{
if ([%H]SortedData!col(ii+1)[L]$ == "Line_Point_No")) ;
}
lineno$=$(ii+1);
lineno$=;
169


the variable lineno$ should be 2 instead of 169(especially because the worksheet has only 167 columns). Does anyone know, what I'm doing wrong?

Thanks,
sebbey
3   L A T E S T    R E P L I E S    (Newest First)
couturier Posted - 06/19/2012 : 11:44:23 AM
There a few mistakes:

- if ([%H]SortedData!col(ii+1)[L]$ == "Line_Point_No")) is missing {} into which script such as lineno$=$(ii+1); should be enclosed
So your script will loop from 0 to 167. After the 167th iteration, ii is incremented (and is equal to 168), compared to numcols and escape the loop. You're thereafter asking for ii+1 and you get 169.

- [%H]SortedData!col(ii+1)[L]$ is a wrong way for testing longname. You should write:
range rcol=[%H]SortedData!$(ii);
rcol[L]$=;

- didn't check but I wouldn't trust col(ii+1). Origin may think you're referring to a col whose name is "ii+1". In such case, it is better to write col($(ii+1)).

- Why starting your loop at ii=0 ?


An equivalent script should be something like:
int ii;
for (ii=1; ii<=wks.ncols; ii++)
{
range rcol=$(ii);
if (rcol[L]$=="Line_Point_No")
{
break; // escape script once Line_Point_No is found
}
}
ii=;
sebbey Posted - 06/19/2012 : 09:53:40 AM
Than you very much couturier. Not only does your code work, it is also much easier and shorter!

But still, does anyone know where my mistake is?

sebbey
couturier Posted - 06/19/2012 : 09:40:42 AM
Try the following:

range rcol="Line_Point_No";
rcol.index=;

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