Undeclared variable

I am having difficulty passing a string to a function I have created, I always get the following error:

"$geoMatMenu" is an undeclared variable.

this variable is declared at the start of the procedure in the form

string $geoMatMenu;

and assigned a value later in the program using:

$geoMatMenu = optionMenuGrp -label "Material Name" geoMatMenu;

so I am at a loss as to why this error message appears.

Any help gratefully received

TrickyR

Umm... You said your having a problem passing a string to a function, but you aren't passing a string to anything in your example?!?
Perhaps you can post some more of your code...

--g

GDC
yep sorry forgot that bit;-)

the bit where I pass stuff is:

textFieldButtonGrp -label "Materials File" -buttonLabel "Browse" -buttonCommand "textFieldButtonGrp -edit -fileName fileDialog -directoryMask "*.mat" geoMatFileButton; menuCreate(textFieldButtonGrp -query -fileName geoMatFileButton, $geoMatMenu)" -p $geoFrame geoMatFileButton;

The button should pass the $geoMatMenu string to my menuCreate function.

thanks for the prompt reply!

TrickyR

I didn't really manage to read your code cos of the layout, but I guess it's cos you must make it a global string. e.g

global string $hello;
$hello = "ms Robinson";

or whatever.. just make sure you redeclare it wherever you use it (in each different procedure you use it).

Just make sure you give your global procs names that will not clash with other scripts.

HTH.

Thanks for the reply
Have now made it a global variable and it works although I find this a little odd since I have used local variables in other areas of the procedure and they work fine :wink:

TrickyR

Wow, that code is really hard to read. Anytime I have a complex command like that to assign to a button, I try to roll that stuff into the proc I am calling.

So from what I can gather the called proc is menuCreate. Since this is assigned to a button, I am sure you know this needs to be a global proc. The same thing is going on with the variable $geoMatMenu.

When this button is pressed, $geoMatMenu isn't available outside of the procedure that built the button. That procedure has been executed and is gone. By making $geoMatMenu global, you are making sure it stays around.

To avoid the global, the value of $geoMatMenu should be computed inside of the proc menuCreate.

--JeffD