Extracting text wave values to use in duplicate

I'm trying to assign a text wave value to a string variable, it doesn't compile.

I'm missing something obvious I'm sure but need some help seeing it. Can someone explain what I'm doing wrong. Thanks.

Function CopyWaves()

    Wave Listofwaves        //IS a wave where each element is the name of a wave in the "root:rawdata" folder
    String localwavename
    Variable z
    NEWDATAFOLDER/O root:working
    FOR(z=0;z<(numpnts(ListofWaves));z+=1)
        localwavename = ListofWaves[z]
        Duplicate/O root:Rawdata:localwavename, root:working:localwavename
    ENDFOR
   
END
Function CopyWaves()

    Wave/T Listofwaves=root:ListofWaves // a text wave where each element is the name of a wave in the "root:rawdata" folder
    String localwavename
    Variable z
    NEWDATAFOLDER/O root:working
    FOR(z=0;z<(numpnts(ListofWaves));z+=1)
        localwavename = ListofWaves[z]
        WAVE dupThis = root:Rawdata:$localwavename
        Duplicate/O dupThis, root:working:$localwavename
    ENDFOR
   
End

 

You need to tell the complier that 'Listofwaves' is a text wave i.e.

Wave /T Listofwaves

You might also need to chose a different letter than 'z' as your iterating variable as it has special meaning i.e. chunk index of a wave. 

Thank you all very much. The "/T" in the declaration and the "$" in front of "localwavename was the ticket. Thanks. Also good point about using z as a variable. Merry Christmas and a happy new year to everyone. Thanks again

 

ssmith