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
 Column Header
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

sebbey

Germany
70 Posts

Posted - 06/19/2012 :  06:52:55 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

couturier

France
291 Posts

Posted - 06/19/2012 :  09:40:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try the following:

range rcol="Line_Point_No";
rcol.index=;
Go to Top of Page

sebbey

Germany
70 Posts

Posted - 06/19/2012 :  09:53:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

couturier

France
291 Posts

Posted - 06/19/2012 :  11:44:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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=;
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