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
 Checking if Workbook with specific name exists
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

hajo_old

Germany
141 Posts

Posted - 01/23/2003 :  04:19:34 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello, all

In my Origin C code I want to create some workbooks within a project.
The extracted code looks like:


void svMinDruck()
{
// Create the Worksheet
Worksheet wks;
string wksTemplate = "User\\Fup\\vorlagen\\FUP_Data_I.OTW";

wks.Create(wksTemplate);
wks.GetPage().Rename("DataI");
}


If I call the above function the first time, everything is fine
But calling the second time the following error pops up to rename the new workbook window.



How can I test the existance of a specified workbook by Origin-C code, so I haven't to deal with the renaming popup and the new creation is suppressed?

Thanks all

Mike Buess

USA
3037 Posts

Posted - 01/23/2003 :  07:48:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The easiest way to do that is with the LabTalk exist() function...

exist(Data1)=;
0 // nothing by that name
1 // dataset
2 // worksheet
3 // graph
etc

Mike Buess
Origin WebRing Member
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 01/23/2003 :  08:40:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
We found the Rename method problematic as well, and in the next service release it will be changed as


int Rename(LPCSTR lpcszNewName, BOOL bAskIfAlreadyUsed = FALSE);
Return:
1 = given name is used to rename the page successfully,
0 = another name was used to rename the page, either through user input or through internal enumeration.
-1 = user click Cancel when ask for a different name to rename the page when bAskIfAlreadyUsed is set to TRUE.




But in the meantime, maybe you can avoid a rename? If you need to access this later, you can always save the name by GetName(). Origin windows, (pages) must all have unique names, so you may want to use Label for indicating your window with more specific information.


CP




Go to Top of Page

rlewis

Canada
253 Posts

Posted - 01/23/2003 :  10:55:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You may find these OriginC functions usefull ...

string CreateHiddenWorkSheet(string PathToTemplate)
{
Worksheet Wks;
if (Wks.Create(PathToTemplate, CREATE_HIDDEN))
{
string WksName;
if(Wks.GetPage().GetName(WksName))
{
return (WksName);
}
}
return ("");
}

string CreateVisibleWorksheet(string PathToTemplate)
{
Worksheet Wks;
if (Wks.Create(PathToTemplate, CREATE_VISIBLE))
{
string WksName;
if(Wks.GetPage().GetName(WksName))
{
return (WksName);
}
}
return ("");
}
Go to Top of Page

hajo_old

Germany
141 Posts

Posted - 01/24/2003 :  08:13:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hallo, all

thanks for your hints.

I got the problem finally solved by the following code:

WorksheetPage wp;
// Get DataI page from WorksheetPages collection of the project
wp = Project.WorksheetPages("DataI");
if(!wp)
{
wks.Create(wksTemplate);
wks.GetPage().Rename("DataI");
wp = Project.WorksheetPages("DataI");
}
else
{
...
}


A nice weekend so far
HJ Koch
SVDO_Origin1
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