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

mortenhuse

Norway
Posts

Posted - 09/06/2007 :  07:20:08 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7,5
Operating System: Windows XP

Hi Origin,

I have a problem with my simple code regarding exporting selected cols from worksheet to ASCII file. I must say that I am a novice in this field...
I get the: "syntax error in decleration" message. I do not understand the syntax (the first 2 parameters at least) of this argument ExportASCII.

This is my code:


#include <Origin.h>

#include <wksheet.h>

PUBLIC int ExportASCII(LPCSTR lpcszFilename, DWORD dwCntrl, char cSeparator = '\t', int nR1 = 0, int nC1 = 0, int nR2 = -1, int nC2 = -1)

void test_export_ascii()

{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
string strFile = GetSaveAsBox("*.txt");
wks.ExportASCII(strFile, WKS_EXPORT_SELECTED);
}
}



Please Help me... :)

Regards

Morten

Mike Buess

USA
3037 Posts

Posted - 09/06/2007 :  09:03:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Morten,

To get rid of the error message just remove the word PUBLIC from the ExportASCII declaration and add a semicolon at the end of the same line. However, ExportASCII is declared in wksheet.h so there is no need to do so in your function. Also, wksheet.h is included in Origin.h so there is no need to #include it in your function. Just remove both lines and your function will work fine...

#include <Origin.h>

void test_export_ascii()
{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
string strFile = GetSaveAsBox("*.txt");
wks.ExportASCII(strFile, WKS_EXPORT_SELECTED);
}
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/06/2007 09:05:50 AM
Go to Top of Page

mortenhuse

Norway
Posts

Posted - 09/06/2007 :  09:13:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,

Thank you very much for the quick and good reply. I did the changes you said and the compilation goes fine, but unfortunately the exported ascii file is empty. It works fine with th ALL command but I need the SELECTED command. Have tried to change parameters (start end cols and rows). Could it be something wrong in the two first parameteres LPCSTR or DWORD? I do not understand them...

Regards

Morten
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/06/2007 :  09:35:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Morten,

The WKS_EXPORT_SELECTED argument exports only columns that have been selected with the mouse. For example, columns A and C will be exported below. Are any columns highlighted in your worksheet?



Mike Buess
Origin WebRing Member
Go to Top of Page

mortenhuse

Norway
Posts

Posted - 09/06/2007 :  2:12:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Again Mike,

Thanks again for clearing up in my missunderstanding. I see now how the selected argument works. My final goal was to set the range of cols and rows to export, let`s say from nC1=1 to nC2=3 and nR1=0 to nR2=10 for instance. How can that be done in my code??

You ar very helpful. Hope I am not bothering you too much...

Kind regards

Morten
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/06/2007 :  4:30:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
There are a number of ways to do partial export. The intended approach is shown below. Note the peculiarity (possibly a bug) that the indices of the last row (nR2) and column (nC2) must be increased by one in order to export the desired range.

void test_export_ascii()
{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
string strFile = GetSaveAsBox("*.txt");
int nC1 = 1;
int nC2 = 3;
int nR1 = 0;
int nR2 = 10;
wks.ExportASCII(strFile, 0, '\t', nR1, nC1, nR2+1, nC2+1);
}
}


An alternative method is to select the desired range with LabTalk's worksheet -s command. (This is equivalent to selecting the range by hand prior to exporting with your original function.) The command takes LabTalk indices so all column and row indices must be increased by one.

void test_export_ascii()
{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
string strFile = GetSaveAsBox("*.txt");
int nC1 = 1;
int nC2 = 3;
int nR1 = 0;
int nR2 = 10;
string sCmd;
sCmd.Format("work -s %d %d %d %d",nC1+1,nR1+1,nC2+1,nR2+1);
wks.LT_execute(sCmd); // select desired range
wks.ExportASCII(strFile, WKS_EXPORT_SELECTED);
wks.LT_execute("work -s"); // deselect range
}
}

Mike Buess
Origin WebRing Member
Go to Top of Page

mortenhuse

Norway
Posts

Posted - 09/06/2007 :  6:28:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Mike,

Now I have finnished making a small program that will make may day easier.
I must really say that this forum (in this case you Mike) and the possibility to do some (simple) programming for automatisation or more complex calculation in Origin, makes this software a powerful tool and my favourite tool for data processing.

Thank you Mike!

Regards

Morten
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