Simple question on definition of variables/strings

Whenever I compile following code:
#pragma rtGlobals=1 // Use modern global access method. Function test() String /G list = WaveList("*",";","") PopupMenu WaveSelect title="Select wave", pos = {10,40}, value = list, proc=WaveSelectProc, mode = 1 End

I get the error:
Quote:
got "list" instead of a string variable or string function name.

I cannot understand why above code does not compile instead of the fact that I have defined the string variable in the function. The same function will compile without any problem in I define a string named "list" in the root folder using String list in the command line.

The problem seems trivial but I am not able to figure out what mistake I have committed.

Thanks in advance.
You must let the compiler know that the source for value keyword may not exist at compile time. Do this by prepending the "#" symbol to the variable name as in...

PopupMenu WaveSelect title="Select wave", pos = {10,40}, value = #list, proc=WaveSelectProc, mode = 1

Try that, I think it will work for you.

For more information, scan through the examples for various situations involving the value keyword in the command help for PopupMenu.
jtigor is right about using #. If you don't do that, the expression is evaluated at compile time. The # sign causes the expression to be stored away and evaluated at the time the menu is activated.

But my guess is that this isn't what you want anyway. Your menu will show whatever waves existed at the time that WaveList() is assigned to the global variable. It is likely that you really want a menu of whatever waves exists at the time you use the menu. For that use WaveList directly:

... value=WaveList("*", ";", "") ...

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
@johnweeks
I did the same as you suggested (and was working fine) in my previous code, but due to the nature of problem, I have to create new waves but did not want to include those waves in the new menu. So I thought I will create the list beforehand (this I did in a separate function init() but did not show here for the brevity of things) and then refer that that with a string variable "list".

@jtigor and @johnweeks
The #list trick did not work, same error again :(
Try value=#"root:list"

If your global list is not in the root data folder, you will have to alter the path. In fact, it is recommended that you put globals of that nature somewhere other than root.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
abhi2005singh wrote:
but due to the nature of problem, I have to create new waves but did not want to include those waves in the new menu.


In that case you don't need a global string (String/G). A local string will suffice:

Function Test()
    String list = WaveList("*",";","")
    PopupMenu WaveSelect title="Select wave", pos = {10,40}, value = #list, proc=WaveSelectProc, mode = 1
End


The # sign before list is still needed.

There are a lot of ways to set a popup menu's items and it can be confusing. The reference help for PopupMenu explains them in the section "Setting The Popup Menu Items". This particular method is explained under "# followed by a local string variable specifying items".
abhi2005singh wrote:
... I have to create new waves but did not want to include those waves in the new menu...


Another possibility, if you have flexibility in naming your waves, would be to make use of the string match capability of WaveList.