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
 Origin Forum
 Can someone tell me what is wrong with this?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

greadey

UK
Posts

Posted - 02/15/2005 :  11:57:48 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I'm trying to write a function that accepts a worksheet and a column index to process the column. My C is a little rusty so I'm playing around a little and trying to work towards useful code.

Anyway here is my function:

void ColProc (int Index, Worksheet *sht) {

Dataset ds;
int nrows = sht.GetNumRows();
ds.Attach(sht, Index);
for(int ii = 0, int jj = 1; jj <= nrows; ii++,jj++) {
if((ds[ii] - ds[jj]) > 0.1) {

printf("Found the break: %i\n", ii);

}

}

}


I have assumed that I have to pass the worksheet by reference - it has already been defined in the function that calls ColProc and ColProc is called thus;

ColProc(iColnum, &wks);


The compiler complains that there are errors in compiling GetNumRows as well as errors in compiling ColProc.

Thanks in advance for any help.

greadey

Gary Lane

USA
150 Posts

Posted - 02/15/2005 :  3:39:57 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Origin C is based on an ANSI C syntax with C++ extensions so
Origin C supports both pointers (C and C++) and references
(C++ only). In-house we often use references because of ease
of use and clarity. Your code re-written to use references is
below in the functions test and ColProc:


void test(int iCol = 0)
{
Worksheet wks = Project.ActiveLayer();
ColProc(iCol, wks);
}

void ColProc(int Index, Worksheet &sht) // Pass by reference
{
Dataset ds;
int nrows = sht.GetNumRows();
ds.Attach(sht, Index);
for(int ii = 0, jj = 1; jj <= nrows; ii++,jj++)
{
if((ds[ii] - ds[jj]) > 0.1)
{
printf("Found the break: %i\n", ii);
return;
}
}
}


One nice thing about above code is that you can just pass your
Worksheet object from the test program and not have to worry about
correctly using the address of operator & in the function call or
the pointer de-referencer in the called function as I did below
in test2 and ColProc2:


void test2(int iCol = 0)
{
Worksheet wks = Project.ActiveLayer();
ColProc2(iCol, &wks);
}

void ColProc2(int Index, Worksheet* sht) // Pass by pointer
{
Dataset ds;
int nrows = sht->GetNumRows(); // note ->
ds.Attach(*sht, Index); // note * (value of)
for(int ii = 0, jj = 1; jj <= nrows; ii++,jj++)
{
if((ds[ii] - ds[jj]) > 0.1)
{
printf("Found the break: %i\n", ii);
return;
}
}
}


I hope this helps.

Gary
OriginLab

Edited by - Gary Lane on 02/15/2005 3:50:46 PM
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