MEL proc and window string array problem

MEL proc and window string array problem

Anonymous
Not applicable
1,208 Views
6 Replies
Message 1 of 7

MEL proc and window string array problem

Anonymous
Not applicable

I'm trying to change out some text in the UI from an array by pressing a button, but I get the error "$names" is an undeclared variable. Please let me know what I am doing wrong here:

 

//procedure goes first
global proc UseArray()
{
    //define variables
    string $names[] = {"Bob", "Jim", "Linda", "Susan"};
    int $index;
$index +=1;
}

//make the window
string $window = `window -title "Choose Name"`; // declares a variable name for the window
columnLayout; // defines the layout type
text -label $names[$index];

button -label "ChangeName" -command "UseArray"; // Use the procedure here as button command

showWindow $window;

 




0 Likes
Accepted solutions (2)
1,209 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Accepted solution

You haven't passed the $names variable into the "window" proc. ( which you should make into a proc) 

 

You also haven't passed whatever $index is , into your array

 

also, your UseArray proc doesn't actually do anything. 

 

I'm not even sure what is supposed to be happening here as nothing is being passed, or returned , or edited

 

-=s

 

 

 

0 Likes
Message 3 of 7

mcw0
Advisor
Advisor
Accepted solution
//procedure goes first
global proc UseArray()
{
     global int $nameIndex;
    //define variables
    string $names[] = {"Bob", "Jim", "Linda", "Susan"};
    int $index = $nameIndex%size($name);
    text -e -label $names[$index] nameTXT;

    $nameIndex+=1;
}

global int $nameIndex;
$nameIndex = 0;
//make the window
string $window = `window -title "Choose Name"`; // declares a variable name for the window
columnLayout; // defines the layout type
text -label "Bob" nameTXT;

button -label "ChangeName" -command "UseArray"; // Use the procedure here as button command

showWindow $window;
0 Likes
Message 4 of 7

Anonymous
Not applicable

!

0 Likes
Message 5 of 7

Anonymous
Not applicable
Ha, there is definitely some missing code there! I was trying to change the text in the window on button press. It was the global variable definition that was tripping me up. Thanks for your response
0 Likes
Message 6 of 7

Anonymous
Not applicable
That worked. Thank you!

I'm still trying to wrap my head around why the variable $nameIndex needs to be defined as a global variable both inside and outside of the procedure
0 Likes
Message 7 of 7

mcw0
Advisor
Advisor

The "UseArray" function has no arguments.  Yet it depends on an incremental change in the array index of the "names" variable to function as desired.  To track the index, you need a variable that is accessible any time...hence the global variable.

0 Likes