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
 Forum for Origin C
 Column Name reference issue
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Lara Cowan

USA
9 Posts

Posted - 11/07/2014 :  2:41:09 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I have a coding question.

An engineer using Origin 9.1 could not get his data to plot while others using 9.0 could plot without issues.
I found that the issue was caused by an overly long column name.

Worksheet wksFilesSetup;
wksFilesSetup.Create();
bOK=wksFilesSetup.ImportASCII(dataDirectory+"\\Files.txt",false,ASCIMP_MODE_REPLACE_DATA,true);   
// Rename setup worksheet page
wksFilesSetup.GetPage().Rename("FileSetup");
string fileSetupName = wksFilesSetup.GetPage().GetName();

Dataset ddTimeColumnIndex(fileSetupName+"_FirstTimeColumnIndex");
StringArray timeColumnIndexArray;
bOK=ddTimeColumnIndex.GetStringArray(timeColumnIndexArray);


Both Origin 9.0 and Origin 9.1 truncate "FirstTimeColumnIndex" to "FirstTimeColumnInd" for the column short name.
Origin 9.0 has no issues getting the column data.
However, Origin 9.1 will not find the column and will set timeColumnIndexArray to Invalid Value.
This means that when timeColumnIndexArray is accessed, Origin will halt with an unkown error.

I changed the line to
Dataset ddTimeColumnIndex(fileSetupName+"_FirstTimeColumnInd");

and then the code worked just fine.

Is there a better way to reference the column or some way to indicate that I want to get the column by long name?

greg

USA
1378 Posts

Posted - 11/10/2014 :  12:24:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It is true that there are character limits for the length of a dataset name which is based on BookShortName_ColumnShortName@SheetIndex
so there are times when Origin automatically truncates a column short name to keep within the limits.
For example, given Book1 with two sheets, the short name of a column in Sheet1 cannot exceed 18 characters. For Sheet2 that limit is 16 characters to accomodate the additional "@2" in the dataset name. (The first sheet never requires an "@1".)

The GUI checks in Origin 9 and 9.1 are the same, so some other process has triggered the difference in the auto-renaming in 9 and 9.1. Note that your workbook rename could actually result in a dropped character if the import had already run into the name limits which is why line following is needed.

The class constructor for a Dataset also includes:
Dataset( Worksheet & wks, int nCol )
and
Dataset( LPCSTR lpcszWksName, int nCol )

which attach to a column based on column index (indexed from 0) and either a worksheet object (wksFilesSetup) or the 'Worksheet name' (e.g. "[Book1]Sheet1", 0 for the first column in Sheet1 of Book1).

Either way, column index is a better way of attaching to a column.
Go to Top of Page

Lara Cowan

USA
9 Posts

Posted - 11/12/2014 :  10:06:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for the information Greg.

I can use the Dataset( Worksheet & wks, int nCol ) constructor for the setup worksheets, but I will have to find a better way to reference the data columns since I will not know their index, only their long name.
Go to Top of Page

Castiel

343 Posts

Posted - 11/12/2014 :  9:42:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Lara Cowan

Thank you for the information Greg.

I can use the Dataset( Worksheet & wks, int nCol ) constructor for the setup worksheets, but I will have to find a better way to reference the data columns since I will not know their index, only their long name.



Datasheet::FindCol(LPCSTR lpcszColLabel, int nColBegin = 0, BOOL bCaseSensitive = false, BOOL bFullMatch = true, int nColEnd = -1, BOOL bAllowShortName = true)


妾+   午旦  妹罕妾  妾伊    用仇  妾/     岫ㄞ
 妾京用 仍巨  件 侈   件戶' 甘岫平   /欠  白岫妹
   併             艮          岫  奈 白   岫
                              岫
Go to Top of Page

Lara Cowan

USA
9 Posts

Posted - 11/13/2014 :  09:18:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Castiel, that works perfectly.
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