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
 All Forums
 Origin Forum
 Origin Forum
 Can someone tell me what is wrong with this?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
greadey Posted - 02/15/2005 : 11:57:48 AM
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
1   L A T E S T    R E P L I E S    (Newest First)
Gary Lane Posted - 02/15/2005 : 3:39:57 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000