String variable made with other variables?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

String variable made with other variables?

pognonec
Hi list,

I want to write a Macro to create substacks with variables to define of the portion to cut out.
I have variable "b" and "e" that store the beginning and ending frames of the deletion needed.
I would like to store in a variable "d" the string:
b-e
so I can use this string variable to set-up the deletion needed in:
run("Make Substack...", "delete slices=&d");

I cannot get this variable d to store a string containing the b and e values with a dash in between...

Any suggestion would be appreciated.

Thanks,
Philippe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: String variable made with other variables?

ctrueden
Hi Philippe,

> I cannot get this variable d to store a string containing the b and e
> values with a dash in between...

Try this:

  d = b + "-" + e;
  run("Make Substack...", "delete slices=" + d);

Or shorter:

  run("Make Substack...", "delete slices=" + b + "-" + e);

See also:

  http://imagej.net/Introduction_into_Macro_Programming#Using_variables

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - http://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - http://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Thu, Feb 25, 2016 at 9:55 AM, Philippe P <[hidden email]> wrote:

> Hi list,
>
> I want to write a Macro to create substacks with variables to define of
> the portion to cut out.
> I have variable "b" and "e" that store the beginning and ending frames of
> the deletion needed.
> I would like to store in a variable "d" the string:
> b-e
> so I can use this string variable to set-up the deletion needed in:
> run("Make Substack...", "delete slices=&d");
>
> I cannot get this variable d to store a string containing the b and e
> values with a dash in between...
>
> Any suggestion would be appreciated.
>
> Thanks,
> Philippe
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: String variable made with other variables?

lechristophe
In reply to this post by pognonec
Hi Philippe,

In a classical macro way you would concatenate the sting directly like this:

run("Make Substack...", "delete slices=" + b + "-" + e);

Would this work for you?

Christophe

On Thu, Feb 25, 2016 at 4:55 PM, Philippe P <[hidden email]> wrote:

> Hi list,
>
> I want to write a Macro to create substacks with variables to define of
> the portion to cut out.
> I have variable "b" and "e" that store the beginning and ending frames of
> the deletion needed.
> I would like to store in a variable "d" the string:
> b-e
> so I can use this string variable to set-up the deletion needed in:
> run("Make Substack...", "delete slices=&d");
>
> I cannot get this variable d to store a string containing the b and e
> values with a dash in between...
>
> Any suggestion would be appreciated.
>
> Thanks,
> Philippe
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: String variable made with other variables?

pognonec
In reply to this post by pognonec
Thanks Curtis and Christophe for your help.
Indeed,
run("Make Substack...", "delete slices=" + b + "-" + e);
does the job.
But I cannot set a variable string containing other variables to work. Curtis suggestion unfortunately does not work either. For example, if you try:
b= 10;
e = 2;
d = "b + "-" + e";
print(d)

You get an error on "-"
:-(

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: String variable made with other variables?

CARL Philippe (LBP)
Dear Philippe,
You need to do:
b= 10;
e = 2;
d = b + "-" + e;
print(d)
My best regards,
Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Philippe P
Envoyé : vendredi 26 février 2016 11:03
À : [hidden email]
Objet : Re: String variable made with other variables?

Thanks Curtis and Christophe for your help.
Indeed,
run("Make Substack...", "delete slices=" + b + "-" + e); does the job.
But I cannot set a variable string containing other variables to work. Curtis suggestion unfortunately does not work either. For example, if you try:
b= 10;
e = 2;
d = "b + "-" + e";
print(d)

You get an error on "-"
:-(

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: String variable made with other variables?

lechristophe
In reply to this post by pognonec
Hi,

As b and e are variable, they have to be outside the "".

b= 10;
e = 2;
d = b + "-" + e;
print(d);

will work. Or if you want to be really sure that it will be picked as a
string:

b= 10;
e = 2;
d = "" + b + "-" + e;
print(d);

Christophe

On Fri, Feb 26, 2016 at 11:03 AM, Philippe P <[hidden email]> wrote:

> Thanks Curtis and Christophe for your help.
> Indeed,
> run("Make Substack...", "delete slices=" + b + "-" + e);
> does the job.
> But I cannot set a variable string containing other variables to work.
> Curtis suggestion unfortunately does not work either. For example, if you
> try:
> b= 10;
> e = 2;
> d = "b + "-" + e";
> print(d)
>
> You get an error on "-"
> :-(
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: String variable made with other variables?

pognonec
In reply to this post by pognonec
Hi Philippe and Christophe,

I got tired fighting with that, and screwed up in my last answer. I did mean, as you suggested:
b= 10;
e = 2;
d = b + "-" + e;
print(d);

This is what does not work, "-" being error.

BUT Christophe's second proposal does work :-)
b= 10;
e = 2;
d = "" + b + "-" + e;
print(d);


Thanks to all!
Philippe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html