Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to make Com Automation Server global?

Subject: How to make Com Automation Server global?

From: Giuseppe

Date: 18 Oct, 2009 20:59:03

Message: 1 of 3


For example, I first build a server in a function
function a1
 h= actxserver('progid')
DES = invoke(h,'CreatenewDesign');

then, in another function I need to call the server to calculate
function b2
wt=invoke(DES,'GetVariable', ***);
invoke(h,'quit');

It will appear 'h' and 'DES' aren't defined, even if I define 'global h' or 'global DES'.
I wonder whether it is not possible to make the handle of a server global? Is there any solution?

Subject: How to make Com Automation Server global?

From: Steven Lord

Date: 19 Oct, 2009 02:44:36

Message: 2 of 3


"Giuseppe " <motognere@gmail.com> wrote in message
news:hbfvin$2kd$1@fred.mathworks.com...
>
> For example, I first build a server in a function
> function a1
> h= actxserver('progid')
> DES = invoke(h,'CreatenewDesign');
>
> then, in another function I need to call the server to calculate
> function b2
> wt=invoke(DES,'GetVariable', ***);
> invoke(h,'quit');
>
> It will appear 'h' and 'DES' aren't defined, even if I define 'global h'
> or 'global DES'.
> I wonder whether it is not possible to make the handle of a server global?
> Is there any solution?

If you declare a variable as global, you must also declare it as global in
EACH AND EVERY workspace in which you want to use the global variable.
Simply defining it in one of those workspaces (say the workspace of function
a1, as I suspect you've done) is not sufficient.

I probably wouldn't use global variables in this situation -- have a1 return
h and DES or have it store them somewhere (using SETAPPDATA, or SETting the
UserData property of some graphics object that your code uses) and either
pass them into b2 or retrieve them from where you've stored them.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: How to make Com Automation Server global?

From: Giuseppe

Date: 19 Oct, 2009 08:44:02

Message: 3 of 3

Thank you so much!


"Steven Lord" <slord@mathworks.com> wrote in message <hbgjpc$fp3$1@fred.mathworks.com>...
>
> "Giuseppe " <motognere@gmail.com> wrote in message
> news:hbfvin$2kd$1@fred.mathworks.com...
> >
> > For example, I first build a server in a function
> > function a1
> > h= actxserver('progid')
> > DES = invoke(h,'CreatenewDesign');
> >
> > then, in another function I need to call the server to calculate
> > function b2
> > wt=invoke(DES,'GetVariable', ***);
> > invoke(h,'quit');
> >
> > It will appear 'h' and 'DES' aren't defined, even if I define 'global h'
> > or 'global DES'.
> > I wonder whether it is not possible to make the handle of a server global?
> > Is there any solution?
>
> If you declare a variable as global, you must also declare it as global in
> EACH AND EVERY workspace in which you want to use the global variable.
> Simply defining it in one of those workspaces (say the workspace of function
> a1, as I suspect you've done) is not sufficient.
>
> I probably wouldn't use global variables in this situation -- have a1 return
> h and DES or have it store them somewhere (using SETAPPDATA, or SETting the
> UserData property of some graphics object that your code uses) and either
> pass them into b2 or retrieve them from where you've stored them.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us