Quantcast

A question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

A question

contacts
Hello,

I am trying to use BeanShell for something that I don't know if it is ever possible...Plese tell me is there a way to do it or stop wasting time on this.

I have these visual elements:

Label a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;

I have an array of words:

String[] words = result.split(" ");

This code works fine:

a1.setText(words[0]);
a2.setText(words[1]);
a3.setText(words[2]);
a4.setText(words[3]);
a5.setText(words[4]);
a6.setText(words[5]);
a7.setText(words[6]);
a8.setText(words[7]);
a9.setText(words[8]);
a10.setText(words[9]);

But what if I have not 10 but 100 elements...So I try to use this:

for (int i=0;i<=maxwords;i++) {
        Interpreter interpreter = new Interpreter();
        try {
                interpreter.set("tmp",words[i]);
                interpreter.set("a","a"+String.valueOf(i));
                interpreter.eval("a.setText(tmp)");
        } catch (EvalError e2) {
                e2.printStackTrace();
        }
}

The problem is with this command:

interpreter.set("a","a"+String.valueOf(i));

If I use this:

interpreter.set("a",a1);
 
Everything is OK but what is the point to call all elements one by one again?

Best wishes

Georgi Bonchev

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A question

Alexey Zinger
I have a feeling, this should work:
interpreter.set("a", interpreter.get("a" + i));

But why are you doing it like that?  Wouldn't it be easier to manipulate a collection or array of of these labels rather than hand-manipulating interpreter's namespace?

 
Alexey




________________________________
 From: "[hidden email]" <[hidden email]>
To: [hidden email]
Sent: Monday, September 17, 2012 9:06 AM
Subject: [Beanshell-users] A question
 
Hello,

I am trying to use BeanShell for something that I don't know if it is ever possible...Plese tell me is there a way to do it or stop wasting time on this.

I have these visual elements:

Label a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;

I have an array of words:

String[] words = result.split(" ");

This code works fine:

a1.setText(words[0]);
a2.setText(words[1]);
a3.setText(words[2]);
a4.setText(words[3]);
a5.setText(words[4]);
a6.setText(words[5]);
a7.setText(words[6]);
a8.setText(words[7]);
a9.setText(words[8]);
a10.setText(words[9]);

But what if I have not 10 but 100 elements...So I try to use this:

for (int i=0;i<=maxwords;i++) {
    Interpreter interpreter = new Interpreter();
    try {
        interpreter.set("tmp",words[i]);
        interpreter.set("a","a"+String.valueOf(i));
        interpreter.eval("a.setText(tmp)");
    } catch (EvalError e2) {
        e2.printStackTrace();
    }
}

The problem is with this command:

interpreter.set("a","a"+String.valueOf(i));

If I use this:

interpreter.set("a",a1);

Everything is OK but what is the point to call all elements one by one again?

Best wishes

Georgi Bonchev

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A question

contacts
In reply to this post by contacts
It did not help but you are right - it will be better to use an array of elements.

Thanks

Alexey Zinger <[hidden email]> wrote:

>I have a feeling, this should work:interpreter.set("a", interpreter.get("a" + i));
>But why are you doing it like that?  Wouldn't it be easier to manipulate a collection or array of of these labels rather than hand-manipulating interpreter's namespace?
> Alexey
>
>
>From: "[hidden email]" <[hidden email]>
>To: [hidden email]
>Sent: Monday, September 17, 2012 9:06 AM
>Subject: [Beanshell-users] A question
>
>Hello,
>
>I am trying to use BeanShell for something that I don't know if it is ever possible...Plese tell me is there a way to do it or stop wasting time on this.
>
>I have these visual elements:
>
>Label a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
>
>I have an array of words:
>
>String[] words = result.split(" ");
>
>This code works fine:
>
>a1.setText(words[0]);
>a2.setText(words[1]);
>a3.setText(words[2]);
>a4.setText(words[3]);
>a5.setText(words[4]);
>a6.setText(words[5]);
>a7.setText(words[6]);
>a8.setText(words[7]);
>a9.setText(words[8]);
>a10.setText(words[9]);
>
>But what if I have not 10 but 100 elements...So I try to use this:
>
>for (int i=0;i<=maxwords;i++) {
>    Interpreter interpreter = new Interpreter();
>    try {
>        interpreter.set("tmp",words[i]);
>        interpreter.set("a","a"+String.valueOf(i));
>        interpreter.eval("a.setText(tmp)");
>    } catch (EvalError e2) {
>        e2.printStackTrace();
>    }
>}
>
>The problem is with this command:
>
>interpreter.set("a","a"+String.valueOf(i));
>
>If I use this:
>
>interpreter.set("a",a1);
>
>Everything is OK but what is the point to call all elements one by one again?
>
>Best wishes
>
>Georgi Bonchev
>
>------------------------------------------------------------------------------
>Live Security Virtual Conference
>Exclusive live event will cover all the ways today's security and
>threat landscape has changed and how IT managers can respond. Discussions
>will include endpoint security, mobile security and the latest in malware
>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>
>Beanshell-users mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/beanshell-users
>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Loading...