Waves from indexed tables

I'm a new Igor programmer, and having trouble with the WaveRefIndexed function. I've successfully used the XLLoadWave function to pass in data from Excel, but I can't seem to use the WaveRefIndexed function to properly reference the data as particular waves. When I try to compile, an error message reads, "ambiguous wave point error" and points to the end parenthese on line 3 of the code below:

    XLLoadWave/R=(A2,Z400)/O/I/T/W=1/C=2 "Choose Columns Containing Abundance Values"
    String AbundTable = WinName(0,2,1)
    String AbundWave1str = WaveRefIndexed("AbundTable",0,1)
    Wave AbundWave1 = $AbundWave1str


Am I using the WaveRefIndexed function incorrectly, or is it possible that there is a bug in the wave referencing here? I'm using version 6.22A.
This is incorrect:
    String AbundWave1str = WaveRefIndexed("AbundTable",0,1)

It should be this:
    String AbundWave1str = WaveRefIndexed(AbundTable,0,1)


The first specifies a table literally named AbundTable. The second specifies a table whose name is stored in the string variable AbundTable.
I have a similar problem:

working:
string specname=Wavename(graphname,specnum,1)
Duplicate /O/R=(xl,xr) $specname $remname,$backname


not working:
string specname=WaveRefIndexed(graphname,specnum,1)
Duplicate /O/R=(xl,xr) $specname $remname,$backname

This gives a "ambiguous wave point error".

But instead this is working again:
Duplicate /O/R=(xl,xr) WaveRefIndexed(graphname,specnum,1) $remname,$backname


But I need WaveRefIndexed(graphname,specnum,1) as a variable.
Any suggestions?
Callisto wrote:
working:
string specname=Wavename(graphname,specnum,1)
Duplicate /O/R=(xl,xr) $specname $remname,$backname

Here you are getting the wave name as a string from the WaveName function. Then you use the $ operator inline to generate a wave reference.

Quote:
not working:
string specname=WaveRefIndexed(graphname,specnum,1)
Duplicate /O/R=(xl,xr) $specname $remname,$backname

In this case, the WaveRefIndexed function returns a wave reference, not a string. So it is ready for your use as a wave without using the $ operator. You can make a wave reference variable like this:
Wave specwave = WaveRefIndexed(graphname,specnum,1)
Duplicate /O/R=(xl,xr) specwave $remname,$backname
... further uses of specwave as a wave ...

Making a wave reference gives you a variable that can be used just as you would use an actual wave name in a command like Duplicate. It is a stand-in for a wave that is unknown at compile time.

This whole business with $ operator, strings and references can be quite confusing. It took me a while to figure out exactly when I need one or another solution. It can be tricky sometimes to understand from our documentation whether you need (or receive) a string or a reference. But in general, if we document that something returns a "wave name" it is returning a string, and if we document that it returns a "wave reference" then what you get is not a string. In fact, the documentation for WaveName says "returns a string containing the name".

You might want to review some topics in our help files:
DisplayHelpTopic "Accessing Waves In Functions"
DisplayHelpTopic "Converting a String into a Reference Using $"

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com