PDA

View Full Version : How to use button -c flag??


super
06-23-2006, 03:31 PM
Hi~ this is my problem:
I have a subfunction work two string. like this
proc test(string a1,string a2)
{
............
}

In main program , I use a button and his -c flag, I want to call subfunction where button pressed, and pass two strings to subfunction.
i.e. button -c ???????? , write what in the question mark let the button and subfunction can work??

Thanks your help!:)

cpan
06-23-2006, 03:35 PM
$string1 = "AAA";
$string1 = "BBB";
button -c ("test " + $string1 + " " +$string2) myButton;


but i think you need to make the test proc a global one cause it's called from withing the UI and not from the script itself:

global proc test(string $s1, string $s2)
{
...
}

super
06-23-2006, 06:16 PM
Thanks your reply, but it doesn't work!
After I try, I found this:

In your method, it mean : sub AAA BBB , the error is : Wrong number of arguments on call sub.

so I modify that:

string $callfunction="sub $string1 $string2";
button -c $callfunction;

but the error is : undeclared variable, so I change $string1 and $string2 as global variable.
this time , it work..........but I still don't know what's happen, just waste a lot of time to try. :twisted:

Thanks your help!!
If you have interest, here is the code.
-------------------------------------
string $t1="holle to";
string $t2="see you";

global proc test()
{
if(`window -ex testfunction`)
deleteUI testfunction;
window -t "Test" testfunction;
columnLayout;

string $callfunction="sub $t1 $t2";
button -l "test"
-c $callfunction;

setParent -u;
showWindow testfunction;
}
global proc sub(string $a1,string $a2)
{
string $a3=$a1 + " " + $a2;
print $a3;
print "\n";
}
---------------------------------------

cpan
06-24-2006, 06:10 AM
// corrected the script:

global proc test()
{
if(`window -ex testfunction`)
deleteUI testfunction;
window -t "Test" testfunction;
columnLayout;

string $t1="holle to";
string $t2="see you";

string $callfunction=("sub \"" + $t1 + "\" \"" + $t2 + "\";");
// this equals to: sub "holle to" "see you";
// use \" to reproduce a " mark inside another "" marks


button -l "test" -c $callfunction;

setParent -u;
showWindow testfunction;
}
global proc sub(string $a1,string $a2)
{
string $a3=$a1 + " " + $a2;
print $a3;
print "\n";
}


your problem was that you were calling the sub function with the $a1 and $a2 as strings and not variables. That explains why if those $a1 and $a2 were global vars the script would work.

StephG
06-24-2006, 08:06 AM
A simpler approach might be:


if (`window -ex testwindow`)deleteUI testwindow;
window testwindow;

columnLayout;

string $A = "Hello";
string $B = "there";
button -l "test" -c "test \$A \$B" testB;
/*The entire command is in quotes, but the slash can be used to identify the variables*/
showWindow testwindow;

proc test (string $AA, string $BB)
{
print ($AA+ " " + $BB + "\n");
}

CGTalk Moderation
06-24-2006, 08:06 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.