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

jgeskey

USA
Posts

Posted - 05/23/2006 :  12:57:10 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5 SR4
Operating System: WinXP pro

hi,

I'm writing a function to import some ascii text. Once the text is imported I want to format the columns to match the data. Everything works perfectly except formatting the date column. We have our own standard date format I'm stuck with using, its:

yyyyMMdd HHmmss.sssZ

I've added it to the custom2 format under date properties and it works great selecting it manually. The problem is I want my function to do it for me, the user won't be able to select it manually.

what I have is:

wks.Columns(0).SetFormat(OKCOLTYPE_DATE);
wks.Columns(0).SetSubFormat(20);

when the column is automatically set to date, all data is replaced with a dash because origin does not recognize it as a date, before it gets a chance to change the subformat to my custom format. Doing it manually I can select them both at once so the data is not lost. Is there a way I can nest these 2 together?

any help would be much appreciated.










Mike Buess

USA
3037 Posts

Posted - 05/23/2006 :  3:59:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It's tricky to format a Date column by code after it's filled with text because everything turns to missing values. Safer to format the column before you import its values. If that's not possible (I don't know how your are importing) you can create and format a new column and then copy over the date strings like this...

string str1,str2 = wks.Columns(0).GetName();
wks.InsertCol(0,"Date",str1);
wks.Columns(0).SetFormat(OKCOLTYPE_DATE);
wks.Columns(0).SetSubFormat(20);
Dataset ds0(wks,0),ds1(wks,1);
StringArray sa;
ds1.GetStringArray(sa);
ds0.PutStringArray(sa);
wks.DeleteCol(1); // delete original date column
wks.Columns(0).SetName(str2); // rename new date column

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 05/23/2006 5:46:50 PM

Edited by - Mike Buess on 05/24/2006 08:31:43 AM
Go to Top of Page

jgeskey

USA
Posts

Posted - 05/24/2006 :  10:09:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mike,

you the man, wish I had though of that myself. I used your make a new column, format it, copy the data to it, and delete the old column. It works like a charm.

thanks again :-)

john
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