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

gintunas

5 Posts

Posted - 06/19/2009 :  09:29:25 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

I am new in Origin C. I try to assign some numerical values to a created worksheet.

Could somebody indicate why my little code (below) halts with
"general operation failure
general operation failure
general operation failure
general operation failure
Command Error!"

The code is

void InitializeWorksheet(string WorksheetName)
{
Worksheet wks(WorksheetName);

if(!wks)
{
out_str("There is no worksheet with the name "+WorksheetName);
return;
}

printf("Columns %d Rows %d \n",wks.GetNumCols(),wks.GetNumRows());


for(int nCol = 0; nCol < wks.GetNumCols()-1; nCol++)
{
Dataset Temp;
int Size=wks.GetNumRows();
Temp.SetSize(Size);
Temp.Attach(wks, nCol);

for(int nRow = 0; nRow < wks.GetNumRows()-1; nRow++)
{
printf("We are on the row %d\n",nRow);
Temp[nRow]=nRow;
}

}

Iris_Bai

China
Posts

Posted - 06/22/2009 :  03:46:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Runtime error here because when call Temp.SetSize(Size); Temp is an invalid object, should let Dataset attach to one column before SetSize. So change code to:

Temp.Attach(wks, nCol);
Temp.SetSize(Size);


BTW, I saw in for statement "int nCol=0; nCol < wks.GetNumCols()-1", this condition will NOT loop to the last column. If you want to loop to the last column, need change to nCol <= wks.GetNumCols() -1 or nCol < wks.GetNumCols()


Iris
Go to Top of Page

gintunas

5 Posts

Posted - 06/22/2009 :  06:17:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, it works perfectly now!
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