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
 return type "string"
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

datrix

11 Posts

Posted - 08/24/2011 :  07:30:08 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Version: OriginPro 8.1G SR3 v8.1.34.90
Operating System: Windows XP SP3

Hello,

our institute uses the above mentioned Version of Origin and I have two little questions:

1. Problem with return type "string"

simple testcase:


string ReturnString(){
string a="abc";
out_str(a); // Output -> "abc" -> Works
return a;
}


compiles fine but after execution of ReturnString();
on error message appears:

ungültige Argumentanzahl an Funktion übergeben : 
#Command Error!


analogous translation: "invalid number of arguments delivered to function"
The message is not very helpful because the function "ReturnString()" does not have any arguments
What causes this error?

----------------------------

2. When a double click between two columns within a worksheet is performed (in the normal Origin GUI),
the column width exactly changes perfect to the width of the largest cell.
I would like to create the this effect with C++ code, but for example


...
wks.Columns(0).SetWidth();
...


creates not the same effect. How can I solve this problem?

Thanks
datrix

Penn

China
644 Posts

Posted - 08/24/2011 :  11:41:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi datrix,

For problem 1:
Maybe you have not called this Origin C function by using LabTalk statement correctly. I call this Origin C in LabTalk like:

string str$ = ReturnString()$;
str$ = ;

And it works fine. Here, the returned value needs to be assigned to a LabTalk variable, and the $ symbol is needed. You can find the related contents from the help document (Origin C>Programming Guide>Introduction to Origin C>Calling Functions>Calling Origin C from LabTalk>Returning Variables to LabTalk>Returning String).

For problem 2:
It is a bug and we will try to fix it. Thanks for reporting this.

Penn
Go to Top of Page

datrix

11 Posts

Posted - 08/25/2011 :  07:05:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Penn,

thank you for your answer.
For the string return it works now, but what about returning structs?

example: (Building small GUI with 2 checkboxes and return
the struct that catches the values the user set)



#include <Origin.h>
#include <GetNbox.h>

typedef	struct tagGUIValues{
	bool a;
	bool b;
	bool bGUICanceld;  
} GUIVALUES;


GUIVALUES openGUI(){
	
   GUIVALUES gv;
	
   // Build GUI 
   GETN_TREE(tr)
   GETN_CHECK(a, "Checkbox 1", false)
   GETN_CHECK(b, "Checkbox 2", true)
		
   // initialize GUI and read values into struct
   if(GetNBox(tr, "label text", "some other text")){
       gv.a = tr.a.nVal;
       gv.b = tr.b.nVal;
       gv.bGUICanceld = false;
       return gv;
   }

   else {
       gv.bGUICanceld = true;
       out_str("GUI canceld!");
       return gv;
   }
}


This is definetly corect code and compiles fine, runs fine, but creates the same
error message as with the "return string" example above.

-------------------------------------------

Another question concernig basic I/O operations
we have

out_int("number is = ",12); //for int
out_str("number is = 12"); // for strings
out_double("number is = ",12.00); //for double
out_tree ... // for trees

what about something like "out_bool();"
Does s.th. like this exists?

greets
datrix
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 08/25/2011 :  9:59:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
1. return struct is probably not supported in Origin C, and you can easily pass in the struct by pointer or reference, like

bool openGUI(GUIVALUES & gv){
gv.a = tr.a.nVal;
return true;

}


2. bool is internally an int, so you can just use out_int for those.

CP
Go to Top of Page

datrix

11 Posts

Posted - 08/26/2011 :  09:51:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you.

I think it is supported.
I can use all of those functions returning string and struct and all other types, when
enclosing it into a void function.

void vCall_openGUI(){

   GUIVALUES gv;
   gv = openGUI();

   if (gv.a == true/false){//do s.th.}
   if (gv.b == true/false){//do s.th.}
   if (gv.bGUICanceld == true/false){//do s.th.}
}

LT prompt:

>> vCall_openGUI() //<--- Will not create some error messages and works quite good.


I was just wondering why the error message is created when calling "openGUI()" directly.

greets
datrix
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